Hello.
So what I am trying to do is make a randomly generated ghost NPC teleport to a random point inside of a separate folder.
The problem is that each time the NPC is teleported, it returns the number 6, and I do not know why.
Error:
Here is the code; (This code is for testing purposes, so for now, this would go inside of a ServerScript, inside of workspace).
local points = workspace:WaitForChild("Points")
local ghosts = workspace:WaitForChild("Ghosts")
local tweenservice = game:GetService("TweenService")
local test_t = 0.2
local active = true
task.spawn(function()
while active do
local randompoint = points[math.random(1, #points:GetChildren())]
local randomghost = ghosts[math.random(1, #ghosts:GetChildren())]
if randomghost then
randomghost:WaitForChild("HumanoidRootPart").CFrame = randompoint.CFrame
end
task.wait(test_t)
end
end)
Can anyone help me get a solution to this? Thank you.