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

NPC trying to move to closest character erroring why?

Im trying to make an npc follow since hes the bad guy trying to "kill me". This is my code

local closesdistance = 100 
while wait(1) do
	if game.Lighting.TimeOfDay == "00:00:00" then
		if (game.Players.LocalPlayer.Character.HumanoidRootPart.Position - game.Workspace.badguy.HumanoidRootPart.Position).Magnitude < closesdistance then
			game.Workspace.badguy.Humanoid:MoveTo(game.Players.LocalPlayer.Character.HumanoidRootPart)
			
		end
	end
end

I keep getting an error that says: 16:41:55.862 - Unable to cast Instance to Vector3. What does this mean?

1 comment

0

i recommend just using path finding https://developer.roblox.com/en-us/articles/Pathfinding

1 answer

Try

game.Workspace.badguy.Humanoid:MoveTo(game.Players.LocalPlayer.Character.HumanoidRootPart.Position)

MoveTo() needs a Vector3 point, so just add .Position to where it's going to move.

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