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

My script for a clone of an npc to come forward not working?

So I have a script which when a player clicks a button, a clone of an npc comes forward to ask the person what he wants. This thing doesn't seem to work for me. Any help? Here is my script:

local de = 1
function onTouch(plr)
	if de == 1 then
de = 2
print("recieved")
	
  local char = game.Workspace.NPC:Clone()

        local torso = char:FindFirstChild("HumanoidRootPart") -- The humanoid root part of the cahracter

        local pos = (torso.CFrame:pointToWorldSpace(Vector3.new(0, 0, 10))) -- A position from the world space, 5 studs to the left of the humanoid root part.
  local hum = char:WaitForChild("Humanoid") -- Identifies the humanoid of the player.


        hum.WalkToPoint = pos -- Changes the walking point of the humanoid to walk towards that position.


end
end

script.Parent.ClickDetector.MouseClick:Connect(onTouch)

4 comments

0

use MoveTo() instead of WalkToPoint

0

MoveTo() on a Humanoid causes it to walk to a given Vector3, MoveTo() on a character causes the character to teleport to the given Vector3

0

more specifically, :MoveTo() called on a model moves the model to the given Vector3

0

MoveTo() on a model tends to be frowned upon, if you were to "teleport" a model then you should be using SetPrimaryPartCFrame

1 answer

MoveTo() on a model will teleport that model to the given location based on a Vector3, similar to how SetPrimaryPartCFrame (however that takes a CFrame value)

If you want to an NPC then you should be using MoveTo on that NPC's humanoid rather then the model itself. Please see the Wiki next time.


local Humanoid = char:WaitForChild("Humanoid")
local Location = Vector3.new(0, 0, 10)
Humanoid:MoveTo(Location)

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