Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why is Humanoid:MoveTo functioning strangely?

I've been trying to figure out why this happens, but I just can't for the life of me figure it out. Local script:

local cam = workspace.CurrentCamera
local hum = workspace.FINSKMANN.Humanoid
local debounce = false

local function Chat(msg)
	game.Chat:Chat(workspace.FINSKMANN.Head, msg, Enum.ChatColor.White)
end

game.ContextActionService:BindAction('Start', function()
	game.Players.LocalPlayer.PlayerGui.ScreenGui:ClearAllChildren()
	
	if not debounce then
		debounce = true
		cam.CameraType = 'Scriptable'
		
		game:GetService('RunService').RenderStepped:Connect(function()
			cam.CFrame = CFrame.new(workspace.CamPos.Position, workspace.CamRot.Position)
		end)
		
		wait(2)
		
		Chat("Maybe it wasn't the best idea to go camping ALONE, especially here in the Cosaqiezsa forest...")
		hum:MoveTo(Vector3.new(-4.5, 0, 8.5))
		local prevTick = tick()
		hum.MoveToFinished:Wait()
		print(tick() - prevTick)
		
		wait(2.25)
		
		Chat('Whatever.. Surely it can not get that bad.')
	end
end, false, 'g')

If I provide no input after I press G, 8 prints out (because the :MoveTo function times out after 8 seconds if humanoid has not yet reached provided Vector3). If I walk behind FINSKMANN (the character), then FINSKMANN moves.

I'm no ROBLOX physics expert, so any help is appreciated.

4 comments

0

Not sure if this is the issue, try using :MoveTo() on the character model instead of the humanoid.

0

Humanoid:MoveTo(waypoint.Position) Basically you need position and a waypoint to move at, I used waypoint cause it was my parts name to go to so yeah you have to do the same.

0

Just using vector3 functions like crap, that's your problem. Use a part to track where he goes.

0

I added a part and set that part's position to the same as the Vector3 value I used, and the same problem occoured.

1 answer

First, I don't know if it will work or not. But, I am sure that it might be the problem of NetworkOwnership. And, if the 'FINSKMANN' is a NPC, it might be the problem. To fix it, add this line before :MoveTo():

-- Make sure you have it inside ContextActionService, and before :MoveTo() part

local rootPart = workspace.FINSKMANN.PrimaryPart
rootPart:SetNetworkOwner(nil) -- nil is 'Server'

More info on Network Ownership

Lemme know if it helps!

5 comments

0

Gotcha, I'll try it.

0

It returns the error: Network Ownership API can only be called from the Server., as function is being called from a local script. To counter this, I just added the same variable & function to a seperate server script. The only difference it made was that FINSKMANN would no longer move to the position if I moved behind him.

0

Well, then in order to debug the issue, test the game using 'Run', and disable that script and add another script with just movement only. Then. test the game and see if the NPC moves to the position. MAKE SURE TO TEST IT AS 'RUN'.

0

It did work, FINSKMANN did move to the spot. I'm thinking now that i should just use a remote event.

0

So, its the problem of Network Ownership only. Try moving the humanoid on RemoteFunction trigger on Server side and set network owner to nil there only, then as the response of the RemoteFunction comes, you can resume your local script.

This discussion is preserved as it was. New answers, comments, and votes are closed.