transform.parent not working

void OnCollisionEnter2D(Collision2D stay){
if (stay.gameObject.tag == “Player” && !onPlatform){
player.transform.parent = transform;
onPlatform = true;
}
}
I need to parent my character to a moving platform when they collide, simple as that. onPlatform variable will become true, but the parent instruction will not be executed. Any help appreciated.

Use SetParent instead of what you are using. And make sure you set onPlatform false when exiting.
On the other hand i recommend you to move this to the player’s movement.
and use this structure if you do so

void OnCollisionEnter2D(Collision2D stay){
                 if (stay.gameObject.tag == "Platform" && !onPlatform){
                      //Here you should set the parent of transform to stay.gameObject.transform, you can use both transform.parent or SetParent, it's up to you

                 }
         }

It is very simple you make your player.transform.parent null in every update. Make sure you only make it null if you exit from the platform

Try transform.parent.name