How do I create moving platforms done locally?

Hi, I am currently working on a round-based obstacle course game and I have encountered an issue that has left me confused for the past few days.

My game utilizes a variety of obstacles, one of those being a moving platform. The desired effect that I want it to create is a moving part that can be handled by the client (solves lag issues) that also carries the player using the AlignPosition thing.

Originally, I had accomplished half of this. I had successfully created the tweening effect with AlignPosition, but it only ran server-side. I had seen other games handle it locally, such as Tower of Hell or the obby in Horrific Housing.

However, when I try to move these parts using AlignPosition, a variety of issues arise. I am beginning to wonder how these developers were able to achieve this effect for the client. At the moment, I have a LocalScript inside StarterPlayerScripts which detects the part and tweens the AlignPosition’s position. For some odd reason, though, the server and client don’t seem to co-operate. It seems that anything that occurs on the server MUST be replicated to the client, and anything that happens on the client MUST replicate to the server. I am completely lost, and I would appreciate it if someone were to know an alternative. Thanks.

2 Likes

Client changes don’t replicate to the server unless the client has ownership of the part. By default, unanchored parts give ownership to the closest player, or to the server if there is no nearby player. You can explicitly set who owns physics ownership of a part on the server via the SetNetworkOwner API of parts.

However, in a case where you have multiple people navigating around a part such as in the case of an obstacle course, you don’t want any one client to own the physics because all the other players would experience the same sort of lag as if the server owned it.

One solution here is to create the part on the client so that each client has their own part that is simulated locally. This won’t get replicated to the server because to the server, it does not exist. This would probably be my preferred solution. The only downside is that different players might be seeing platforms in different positions, so one player may see another player “floating” on a platform that isn’t there on the first player’s screen. There’s ways around this, such as syncing up with GetServerTimeNow.

Another option is to have it anchored on the server somewhere and unanchor it on the client to move it, if you don’t want to deal with creating it on the client. If the server changes any properties after the client changes it though, they will replicate down and override your local changes.

5 Likes

Thank you, I will try this. Is it also possible to copy over the part from ReplicatedStorage and still have it done locally? This would be my preferred method over creating it via a LocalScript.

1 Like

Absolutely! Calling :Clone() from the client is still creating it on the client.

2 Likes