Why is this happening when you undetain the player

I’m making a detain system and everything’s working, expect when you for example spin around and undetain the player, the player somehow teleports to another position.
The video for it is here: https://gyazo.com/4db50a2c0608dfb1582c7a4c79595157

the undetain script (A bit shortened):

function unDetain(playerGettingDetained)
	local playerGettingDetainedCharater = playerGettingDetained.Character or playerGettingDetained.CharacterAdded:Wait()

	for _, charPart in pairs(playerGettingDetainedCharacter:GetDescendants()) do
		if charPart:IsA("BasePart") or charPart:IsA("MeshPart") or charPart:IsA("UnionOperation") then
			charPart.Massless = false
			charPart:SetNetworkOwner(playerGettingDetained)
		end
	end

	playerGettingDetainedCharacter.HumanoidRootPart.WeldConstraint:Destroy()

    unDetainClientRemote:FireClient(playerGettingDetained)
end```

(the undetainClientRemote just sets PlatformStand to false and changes the state of the humanoid to RunningNoPhysics on the client)

https://gyazo.com/4db50a2c0608dfb1582c7a4c79595157 sorry this is the correct link

thats because the client is ahead of the server, so what you’re seeing when u spin around is where the other player is on your client while where the other player ends up after being detached is the actual server location of the player

Oh, is there any way to prevent this from happening?

i dont think theres a need to, since itll look normal to the other person just not to the one spinning

But is there still a way to make it so that the position isn’t delayed for the person who is detaining?

You probably have to use a RemoteEvent that passes the player’s character’s position, then set the un-detained character’s position to the one sent by the remote. It’s not really efficient, but if you really want it to be fine for the player that is detaining, this is probably the best way.

Ok I tried your solution, it didn’t make it any better and even more noticable for the player detaining.

Oh. Well then sorry but I don’t know how to help you. That’s weird tho. Did you send it exactly when the player was undetaining the other player?

Yeah, the thing is that the server also sees it like the player detaining, so when the player gets undetained the server and the client undetaining him see the player teleporting

So it might be when you send the position of character that it is still the position before the player got to his real position