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

I cant get an NPC to teleport to a certain position?

Asked by 4 years ago

Basically I have a folder of Customer in the workspace. I try to teleport one of them to a certain position, but It doesn't work and they don't show up. Sometimes its just deletes all the brick parts inside them for some reason

local guiFolder = script.Parent.Gui
local timer = guiFolder.Timer
local jobPartsFolder = game.Workspace:WaitForChild("burgerJobParts")
local charSpawn = jobPartsFolder:WaitForChild("burgerCharacterSpawn")
local charPos = jobPartsFolder:WaitForChild("burgerCharacterPos")
jobRunning = script.Parent:WaitForChild("jobRunning")
local plr = game.Players.LocalPlayer;
local jobFolder = plr.PlayerGui:WaitForChild("Jobs")
local customerFolder = game.Workspace:WaitForChild("Customers")
local numberCustomers = 0

-- Gets the customers and puts them in an array
local customers = customerFolder:GetChildren()
for i = 1, #customers do
    local customer = customers[i]
    numberCustomers = numberCustomers + 1
end

-- Chooses random customer
local rn = Random.new ()
local num = rn:NextInteger ( 1, numberCustomers)

-- Enables Timer
timer.Enabled = true
timer.timerScript.Disabled = false
jobRunning.Value = true


-- Manages Timer
while(jobRunning.Value) do
    if (customers[num]:FindFirstChild("Humanoid"):IsA("Humanoid")) then --// Same principles
        customers[num]:MoveTo(charSpawn.CFrame.Position)
    else
        print(customers[num].Name.." doesn't have a Humanoid.") 
    end

    num = rn:NextInteger ( 1, numberCustomers)
    wait(10)
end

1 answer

Log in to vote
0
Answered by
Y_VRN 246 Moderation Voter
4 years ago

Are you trying to call the Humanoid's "MoveTo()" function? If so...

Line 32

    customers[num]:MoveTo(charSpawn.CFrame.Position)
  

Must be...

    customers[num].Humanoid:MoveTo(charSpawn.CFrame.Position)
  

If you want them to teleport completely...

    customers[num]:SetPrimaryPartCFrame(charSpawn.CFrame.Position + Vector3.new(0,3,0)) -- Teleports the customer a little higher than the charSpawn's actual height to make them not sink. Remove this if your charSpawn is above the floor.
  

The above method requires you to set the customer's models' PrimaryPart first. Click on the PrimaryPart property then set it to the model's HumanoidRootPart or whatever part is in the center of it.

Ad

Answer this question