Reposition other players' character on each client

Hello! I am stuck on the problem about how each client would reposition all other players in a certain way

In the game I am working on, the terrain of the game moves around independently of the server on each client. Each client is then freely allowed to move on their terrain that their client has moved. This causes an issue where other players’ characters are desynced with where they would actually be expected to be in a given client.

This happens because when the player moves on a client, it tells the server the player’s exact position, instead of the position relative to the terrain

Diagram incase my explanation didn’t explain it well. The + being a reference point with equal position on each client, and the circles being individual players/clients

Intended:

reality:

I’m struggling with how I would get the intended effect, where each player appears on each client realtive to where that client is actually relatiuve to that client’s terrain, like shown in the diagram above (again, so sorry for being bad at explaining :folded_hands:)

For reference, this is how my terrain moves. On jump, the terrain rotates 180 degress around the player’s forward direction:

I don’t think the way the terrain movement works is necessary, so I won’t show the code for it, unless asked.

Here is also how the bug looks like. The other player shown is flipping terrain and not being in the intended position

Solution
So far, I have only figured out where to postion the player on each given client, but I am struggling with how I would actually position the character of each player, as the server will override any character position change.

-- part of the terrain. Used to keep track the cframe of the island
local referencePart : Part = workspace.Reference
-- client tells the server that the player has moved and where
local onMoveEvent : RemoteEvent = game.ReplicatedStorage.OnMove
-- server tells each client where a player should be
local movePlayerEvent : RemoteEvent = game.Replicated.MovePlayer

--======= CLIENT #1
local refCFrame = referencePart.CFrame
local plrCFrame = hmpr.CFrame

-- player position as it would be on the server
local plrCFrameOnServer = plrCFrame:ToWorldSpace(refCFrame)
onMoveEvent:FireServer(plrCFrameOnServer)

--======= SERVER

onMoveEvent.OnServerEvent:Connect(function(plr, plrCFrame)
   movePlayerEvent:FireAllClients(plr, plrCFrame)
end)

--======= CLIENT #2
movePlayerEvent.OnClientEvent:Connect(function(plrToMove, plrCFrame)
   -- the position this player should be on this client
   local CFrameOnClient = plrCFrame:ToObjectSpace(reference.CFrame)

  -- what now?
  -- btw, am I using the ToObjectSpace and ToWorldSpace funcs correctly?
end)

If there are any other alternatives methods I should try, please do tell. Any help appreciated. Thanks yall!

Hi there,
One solution is to clone every character model on each client and make the originals transparent on each client. Then, move the copied model.
Around 20 times a second or so, fire a remote event to all clients with a table of server positions and convert that to relative space to allow players to continue moving. You could then use Humanoid:MoveTo on the clones to simulate walking.

i might have a pretty hacky solution to this, since what you’re trying to do seems overly complicated (atleast to me)

you could render other players’ terrain on the server, but make non-owner terrains non-collidable and transparent on other clients (server can see all client terrains, clients can only see their own terrain)
and then, when one client rotates their terrain, if you rotate it on the server, it should keep all positions consistent

is this optimal? probably not
do i have better suggestions? absolutely not

Wouldn’t that cause problems with speech bubbles? since the cloned model won’t match the position of the actual model. Additionally, how would I handle the animations fo each character? Equipping tools? etc

Hm, that is true.
I will be away for a few hours so I’ll try to think of a solution if no one else can.

I don’t see how that would help me correct the position of each character. could you please elaborate?

well, you wouldn’t have to correct the positions, you’d just rotate the terrain of whatever client requested it

but since clients can only see their own terrain, nothing actually changes on their screen
but the client that rotated their terrain will be able to move around on the terrain, while standing on ‘invisible’ parts on other client screens

if this doesn’t work for you then i don’t have any ideas

I think you might be misunderstanding my issue. My goal is that for a client, each other client appears in the same relative position to the terrain as they do on their client. However, because when a client moves, it sends its position relative to world space, the player just appears as it would on the server side, which can cause issues such as the player walking on air, thru walls, etc (from the perspective of another client)

yeah i don’t have a clue :wilted_flower:

The problem is that client server replication of characters is automatic. You would need to create clones of the characters and a custom bubble chat system and tool replication system to get it to work.
You could do this by setting player transparency locally with renderStepped and hiding the chatBubble, then checking if there is a tool in a player’s inventory and copying it to the ‘clone’ player or if a player chatted, using a billboardGui to show it. This isn’t too different to creating something like a mirror, where a clone of the player is made and their movements copied

What you are trying to achieve is quite difficult and as such the script might be a little difficult to create.

HOWEVER, a possible ‘easy’ way you could try is moving the other players every Heartbeat on the client and modifying their positions after every physics calculation to stop the player seeing the character replication affect positions.

I tried your “easy” solution and it turns out all I need to do is change the CFrame of other player’s hmrp on heartbeat, thanks!

Also, if anyone else has a similar issue to mine in the future, in the code I provided in the initial post is slightly incorrect, in client #1, it should be local plrCFrameOnServer = refCFrame:ToObjectSpace(plrCFrame), and in client #2, local CFrameOnClient = reference.CFrame:ToWorldSpace(plrCFrame)