MoveTo() Not working on LocalScripts?

Basically what im trying to do is make an NPC Move 8 seconds after a player joins the game, locally

I experimented with MoveTo On server sided scripts and it worked. But when i move to a local script in StarterPlayerScripts It doesn’t work

local NPC = game.Workspace.R6
local humanoid = NPC.Humanoid
game.Players.PlayerAdded:Connect(function()
	AnimationWalkTrack.Looped = true
	wait(8)
	print("hi")
	NPC.Humanoid:MoveTo(game.Workspace.NPCS.Points.PT1.Position)
	NPC.Humanoid.MoveToFinished:Wait()
	wait(1)
	AnimationWalkTrack:Play()
	NPC.Humanoid:MoveTo(game.Workspace.NPCS.Points.PT2.Position)
	NPC.Humanoid.MoveToFinished:Wait()
	wait(1)
	AnimationWalkTrack:Play()
	NPC.Humanoid:MoveTo(game.Workspace.NPCS.Points.PT3.Position)
	NPC.Humanoid.MoveToFinished:Wait()
end)
1 Like

i am guessing it doesnt work because the player is already added before the event can fire

local NPC = game.Workspace.R6
local humanoid = NPC.Humanoid
local player = game.Players.LocalPlayer
local char = player.Character or player:CharacterAdded:Wait()
task.wait(8)
	AnimationWalkTrack.Looped = true
	print("hi")
	NPC.Humanoid:MoveTo(game.Workspace.NPCS.Points.PT1.Position)
	NPC.Humanoid.MoveToFinished:Wait()
	wait(1)
	AnimationWalkTrack:Play()
	NPC.Humanoid:MoveTo(game.Workspace.NPCS.Points.PT2.Position)
	NPC.Humanoid.MoveToFinished:Wait()
	wait(1)
	AnimationWalkTrack:Play()
	NPC.Humanoid:MoveTo(game.Workspace.NPCS.Points.PT3.Position)
	NPC.Humanoid.MoveToFinished:Wait()

5 Likes

It works, but its just endlessly playing the walk animation but its not moving anywhere

Is the NPC created locally? I assume this can be a problem if not

2 Likes

I changed the player:CharacterAdded:Wait() to player.CharacterAdded:Wait()
And disabled the animation for testing purposes.

The scripts seems to work fine, but, I had to give the NPC’s NetworkOwnership to the client, so the client can move the NPC, now its walking correctly to all points in map.

But that takes me to a question… In order to move an NPC on client side, we should give the NetworkOwnership to all clients?.. that sounds not possible

– Local Script in StarterCharacterScripts:

local NPC = game.Workspace.R6
local humanoid = NPC.Humanoid
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()

--AnimationWalkTrack.Looped = true
--AnimationWalkTrack:Play()
NPC.Humanoid:MoveTo(game.Workspace.NPCS.Points.PT1.Position)
NPC.Humanoid.MoveToFinished:Wait()
wait(1)

NPC.Humanoid:MoveTo(game.Workspace.NPCS.Points.PT2.Position)
NPC.Humanoid.MoveToFinished:Wait()
wait(1)

NPC.Humanoid:MoveTo(game.Workspace.NPCS.Points.PT3.Position)
NPC.Humanoid.MoveToFinished:Wait()

A server script which handles the NetworkOwnership for the client that joins:

game.Players.PlayerAdded:Connect(function(player)
     game.Workspace.R6.HumanoidRootPart:SetNetworkOwner(player)
end)
1 Like

That for sure fix the issue I found, where I had to give the ownership to client.
If the NPC is cloned and parented to workspace by the client, surely that fix that issue

1 Like

No its not (30 letters aeasdshjdes)

I tried doing that but it didn’t work. It just sits there. blankly

Weird, I used your script and works for me when I gave the ownership to client.
But dont try that, would be better if you make the client Clone the NPC and parent it to workspace, that will let the client to move the NPC

I think the reason is because of the rig itself, The rig kind of moves but it doesn’t, With a slight push it works

Is the hipheight correct? Is anything anchored, that shouldn’t be?

1 Like

Yup, thats exactly what I noticed the first time I tried your script, after the push started to walk, thats why I changed the NetworkOwnership to the client. After that the NPC always walks without the push

When your character collides with the NPC, the NetworkOwnership changes to belong to your character:

image

Anyway, the best way is to Clone the NPC and parent it to workspace via the client, to avoid this issue

1 Like

yeah the hipheight is 0, and no nothings anchored

Hipheight shouldn’t be 0 as far as I remember. For example a default characters hipheight is 2, since it’s legs is 2 studs high.

1 Like

He just seems to be floating, And it didn’t fix it
image

Try different amount of HipHeight, just try and error

1 Like

There is also a “AutoHipheight” box you can tick, if you have trouble defining a custom hipheight. But a character wont move correctly if hipheight aren’t set correctly.

1 Like

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