Object getting variables from wrong prefab instance

I’ve got a moving platform prefab and I’ve put two instances of it in my scene. I’ve run into an issue, where it seems like one instance is getting variables from the other instance instead of itself. The problem is apparently in the second line in this code snippet:

Vector3 playerPos = player.transform.position;
playerPos.y = transform.FindChild("Platform").position.y;
				
player.transform.position = playerPos;

This snippet is for making sure that the player stays on top of the platform, and it is working when there’s only one instance of the prefab present. However, it appears to be getting the y-position from the other platform when there’s two. the player hovers in the air, at the same y-position as the platform it is not on top of. There’s no static variables that can be interfering with this.

I assume both platform are named ‘Platform’. And here is the issue: FindChild() will always return the same platform (the first one instantiated in the scene).

You need to name your platform differently (e.g. platform_1, platform_2) or reference them inside an array so that the array index will match each platforms separately.