Tweening causes position difference with client & server

Hello

Recently I’ve encountered a very strange problem. I’m using a tween to move a character, and I’m also making this character rotate. When I rotate him on the client and check where he is on server mode, the character is in completely different positions.

I have tested without the tween animation and there seems to be no position difference between server and client, so clearly the tween is at fault. What should I do?

Here is a video example:

External Media

Here is my script:

local rs = game:GetService("ReplicatedStorage")

local events = rs.Events
local functions = rs.Functions

local mouseMovementEvent = events.MouseMovement

local function Anim(plr,animType)
	local character = game.Players:FindFirstChild(plr).TeamStats.Players.PlayerSelected.Value

	local humanoid = character:WaitForChild("Humanoid")
	local animator = humanoid:FindFirstChildOfClass("Animator")

	if not animator then
		animator = Instance.new("Animator")
		animator.Parent = humanoid
	end

	local MoveAnimation = animator:LoadAnimation(character.Animations:WaitForChild("MoveAnim"))

	MoveAnimation:Play()
	MoveAnimation:AdjustSpeed(10)
	print(MoveAnimation.Speed)


	wait(5)
	game:GetService("TweenService"):Create(character.HumanoidRootPart, TweenInfo.new(5,Enum.EasingStyle.Sine, Enum.EasingDirection.In),{Position = Vector3.new(workspace.movehere.Position.X, character.HumanoidRootPart.Position.Y, workspace.movehere.Position.Z)}):Play() -- will clean the code later, just testing
end

wait(1)
game.Players.PaleNoobs.TeamStats.Players.PlayerSelected.Value = workspace.PlayerTemplate -- i put PaleNoobs just for testing

Anim("PaleNoobs",nil)

mouseMovementEvent.OnServerEvent:Connect(function(plr,mousePosition)
	local part = plr.TeamStats.Players.PlayerSelected.Value.HumanoidRootPart
	
	part.CFrame = CFrame.lookAt(part.Position, Vector3.new(mousePosition.X, part.Position.Y, mousePosition.Z))
end)
3 Likes

Do the character movement in a server script and use a RemoteFunction (server calls client with remotefunction) to gather the mouse position from the client.

1 Like

I’m already pretty much doing this, I use a LocalScript to send the mouse position to the server to rotate the player, then play the tween on a server script. I just dont know why this weird teleportation is happening.

1 Like

Ok. You probably don’t want to use tween, instead change the rotation directly with CFrame. Or make the specified time amount on tween small enough so it can make the requested rotation fast enough.

Actually I already do use CFrame for rotation. I just use Tween to move the player around. That is the cause of the issue.

1 Like

My response is still the same.

1 Like

If you mean use CFrame for movement, then I’ll try it.

1 Like

Alright, so it does work, but I feel like it is acting kind of strange. Is there any way to make it look smother?

Heres a video (I coded it so that it doesn’t move when the the mouse is inside the ring)

Heres the server script.

local rs = game:GetService("ReplicatedStorage")

local events = rs.Events
local functions = rs.Functions

local mouseMovementEvent = events.MouseMovement

local function Anim(plr,animType)
	local character = game.Players:FindFirstChild(plr).TeamStats.Players.PlayerSelected.Value

	local humanoid = character:WaitForChild("Humanoid")
	local animator = humanoid:FindFirstChildOfClass("Animator")

	if not animator then
		animator = Instance.new("Animator")
		animator.Parent = humanoid
	end

	local MoveAnimation = animator:LoadAnimation(character.Animations:WaitForChild("MoveAnim"))

	MoveAnimation:Play()
	MoveAnimation:AdjustSpeed(10)
	print(MoveAnimation.Speed)


	wait(5)
	--game:GetService("TweenService"):Create(character.HumanoidRootPart, TweenInfo.new(5,Enum.EasingStyle.Sine, Enum.EasingDirection.In),{Position = Vector3.new(workspace.movehere.Position.X, character.HumanoidRootPart.Position.Y, workspace.movehere.Position.Z)}):Play() -- will clean the code later, just testing
	
end

wait(1)
game.Players.PaleNoobs.TeamStats.Players.PlayerSelected.Value = workspace.PlayerTemplate -- i put PaleNoobs just for testing

Anim("PaleNoobs",nil)

mouseMovementEvent.OnServerEvent:Connect(function(plr,mousePosition)
	local part = plr.TeamStats.Players.PlayerSelected.Value.HumanoidRootPart
	
	local xDif = mousePosition.X - part.Position.X
	local zDif = mousePosition.Z - part.Position.Z
	
	if xDif < 0 then
		if xDif < -0.25 then
			xDif = -0.25
		end
	else
		if xDif > 0.25 then
			xDif = 0.25
		end
	end
	
	if zDif < 0 then
		if zDif < -0.25 then
			zDif = -0.25
		end
	else
		if zDif > 0.25 then
			zDif = 0.25
		end
	end
	
	part.CFrame = CFrame.lookAt(Vector3.new(part.Position.X + xDif, part.Position.Y, part.Position.Z + zDif), Vector3.new(mousePosition.X, part.Position.Y, mousePosition.Z))
end)

Instead of tweening, why can’t you use :MoveTo on the humanoid? It would probably remove most of the difference between the client and server.

1 Like

:MoveTo just instantly teleports it to the position; I want the character to walk there. In my last reply, you can see I did achieve this, but it is quite glitchy when turning and I want it to look smooth.

No, humanoid:MoveTo makes them walk to the point. Humanoid | Documentation - Roblox Creator Hub

Unfortunately, Humanoid:MoveTo does not fit my situation. It seems there is no way to change the speed or the animation in the way I want it to. It also times out after 8 seconds, and to prevent that you have to keep calling :MoveTo. It seems overly complicated for something that doesn’t help that much, so I would prefer to make my own movement system, which I did make here. My only concern at this point is fixing the glitchy turning as shown in the video that I included.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.