Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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)

0
use MoveTo() instead of WalkToPoint DeceptiveCaster 3761 — 5y
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 DeceptiveCaster 3761 — 5y
0
more specifically, :MoveTo() called on a model moves the model to the given Vector3 Gey4Jesus69 2705 — 5y
0
MoveTo() on a model tends to be frowned upon, if you were to "teleport" a model then you should be using SetPrimaryPartCFrame NodeSupport 32 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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)
Ad

Answer this question