Greetings! I am trying to make a script in which a player is moved to a keycard reader (using humanoid:MoveTo()) and when it reaches the desired position, the script moves the player so that the KeyCard (tool in the backpack) is placed correctly in the reader.
However, there seems to be a weird delay, probably due to the Network Ownership, that makes the movement of the player somewhat delayed after the MoveToFinished has fired.
What I have tried:
- Changing the MoveToFinished:Connect(function()) to MoveToFinished:Wait()
- Changing the NetworkOwner of the HumanoidRootPart to the server, however this is undesirable since the player will experience input lag afterwards.
Here is the script:
function moveto(player)
local reader = script.Parent.Parent.Parent.KeyCardReader
local hum = player.Character.Humanoid
hum:MoveTo(reader.SensorPart.Position+Vector3.new(-1.5,0,1.3))
hum.MoveToFinished:Connect(function(reached)
local Tool = player.Backpack:FindFirstChild("Keycard") or player.Character:FindFirstChild("Keycard")
if Tool and reached then
hum:EquipTool(Tool)
player.Character.HumanoidRootPart.Orientation = reader.SensorPart.Orientation + Vector3.new(0,90,0)
player.Character.HumanoidRootPart.Position = reader.SensorPart.Position+Vector3.new(-1.5,-0.2,2)
end
end)
end
script.Parent.MouseClick:Connect(moveto)
Here is a video showing the problem:
Any solution or idea of how to solve this problem would be greatly appreciated