Why does MoveTo() Do this?

So I have a game where a npc walks toward the player, but when the player is going fast this happens,

https://gyazo.com/108dd50a9f2981a542e1f33b9e04df91.mp4

blue = where its suppose to go
red = where it goes
image

here’s my server script where the npc moves,


game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local hum = char:WaitForChild("Humanoid")
		hum.Touched:Connect(function(hit)
			if hit.Name == "Area" and char.peeps.Value < char.maxpeeps.Value and char and char:FindFirstChild("HumanoidRootPart")  then
				
				hit.CanTouch = false

				local person = hit:FindFirstChild("person")
				
				if person then
					
					char.HumanoidRootPart.Anchored = true
					task.wait()
					person.Peepoid:MoveTo(char.Torso.Position)
					
					
					
			
					
					person.Peepoid.MoveToFinished:Connect(function()
						person:Destroy()
						char.peeps.Value = char.peeps.Value + 1
						local pickupSound = workspace.sounds.pickupsounds:GetChildren()[math.random(1,#workspace.sounds.pickupsounds:GetChildren())]
						game.ReplicatedStorage.playsound:FireClient(player,pickupSound)
						hit.Parent:Destroy()
						char.HumanoidRootPart.Anchored = false
					end)

				else

					hit.Parent:Destroy()
					char.HumanoidRootPart.Anchored = false
				end
			end
		end)
	end)
end)```
5 Likes

why not actively update where the NPC is supposed to be going to?

or you could have the npc wait until the plr is completely done moving and then have the NPC move.

Alright Ill try to implement this, thank you.

1 Like

so this is what i came up with… but there is still the same issue.

local detect = game.ReplicatedStorage.detect

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local hum = char:WaitForChild("Humanoid")
		hum.Touched:Connect(function(hit)
			if hit.Name == "Area" and char.peeps.Value < char.maxpeeps.Value and char and char:FindFirstChild("HumanoidRootPart") then
				hit.CanTouch = false

				local person = hit:FindFirstChild("person")

				if person then
					char.HumanoidRootPart.Anchored = true
					repeat
						wait()
					until char.Humanoid.MoveDirection.Magnitude == 0
					
					person.Peepoid:MoveTo(char.Torso.Position)

					person.Peepoid.MoveToFinished:Connect(function()
						person:Destroy()
						char.peeps.Value = char.peeps.Value + 1

						local pickupSound = workspace.sounds.pickupsounds:GetChildren()[math.random(1, #workspace.sounds.pickupsounds:GetChildren())]
						game.ReplicatedStorage.playsound:FireClient(player, pickupSound)

						hit.Parent:Destroy()
						char.HumanoidRootPart.Anchored = false
					end)
				else
					
					hit.Parent:Destroy()
					char.HumanoidRootPart.Anchored = false
				end
			end
		end)
	end)
end)
2 Likes

dont use movedirection, use the assemblyliniearvelocity property on the hrp

repeat
					wait()
				until char.HumanoidRootPart.AssemblyLinearVelocity == Vector3.new(0,0,0) 

still doesnt work did i do this correctly?

1 Like

(the npc doesnt move at all now)

i looked inside the players humanoidrootpart and this is what it looks like
image

1 Like

yea, so basically, move direction is the player’s input direction and not the movement of the literal character through physical space. Assembly linear velocity is the movement of the assembly.

1 Like

no i meant for the checking. When you go and check if the player isn’t moving anymore, check their assembly linear velocity and not their move direction

1 Like

i think its because of the player is controlled by the client, so the assembly linear velocity will be different from the servers version so the players assembly linear velocity

1 Like

make sure you read this, not sure if you saw it yet

yes thats what i did here.

repeat
wait()
until char.HumanoidRootPart.AssemblyLinearVelocity == Vector3.new(0,0,0)```
1 Like

Use this instead of :MoveTo() to make it not go on top of the player

object:PivotTo(CFrame.new(position))

Rip I didn’t understand your issue so I assumed sorry I don’t think this is what you want

1 Like

ill be back in a bit, i have to go do something.

1 Like

my issue is the npc goes past the player it doesnt coordinate properly

1 Like

so it seems like on the server it goes to the exact positon while on the client it doesnt…

server:
https://gyazo.com/79cf494e5eacbb1ff69b3e831b2a74a6.mp4

client:
https://gyazo.com/97f94e4698e3fbcfca1b51d4448e020c.mp4

1 Like

There is nothing wrong with the script, it’s just how roblox’s system works. If the speed is around 80 or so, he starts to slide. The only fix I think is just to lower the speed of the character.

1 Like

the only problem with this is that in this game u accelerate using the mouse

1 Like