Hello
I recently made a player teleportation script that after a few seconds it teleport the players to a certain place. I used to work maybe it was due to a roblox update. But this this the script anyways.
SCRIPT
function onTouch(hit)
if hit.Parent:FindFirstChild("NPC") then
wait(10)
local TeleportPoint = CFrame.new(24.85, 5.898, 117.04)
for i, player in ipairs(game.Players:GetChildren()) do
if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
player.Character.HumanoidRootPart.CFrame = TeleportPoint + Vector3.new(0, i * 5, 0)
end
end
end
end
script.Parent.Touched:Connect(onTouch)
Hi! when moving players you should either use the MoveTo or SetPrimaryPartCFrame function, here is how it can be used in your scenario:
function onTouch(hit)
if hit.Parent:FindFirstChild("NPC") then
wait(10)
local TeleportPoint = CFrame.new(24.85, 5.898, 117.04)
for i, player in ipairs(game.Players:GetChildren()) do
if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
player.Character:MoveTo(TeleportPoint + Vector3.new(0, i * 5, 0))
end
end
end
end
script.Parent.Touched:Connect(onTouch)
function onTouch(hit)
if hit.Parent:FindFirstChild("NPC") then
wait(10)
local TeleportPoint = CFrame.new(24.85, 5.898, 117.04)
for i, player in ipairs(game.Players:GetChildren()) do
if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
player.Character:MoveTo(TeleportPoint + Vector3.new(0, i * 5, 0))
end
end
end
end
script.Parent.Touched:Connect(onTouch)
What @RomeoEDD has said here accurately displays how your script should look but the one thing I wanted to add is that you should be checking if it’s an actual Character because depending on accessories that the NPC is wearing this script could be void.
function onTouch(hit)
if hit.Parent:FindFirstChild("NPC") then
wait(10)
local TeleportPoint = CFrame.new(24.85, 5.898, 117.04)
hit.Parent:MoveTo(TeleportPoint.P)
end
end
script.Parent.Touched:Connect(onTouch)
What I have removed: Removed the for loop
What I have added: A simple statement, gets the parent of the hit object (The NPC/Player model), and calling the :MoveTo() function on it, which is an in-built function of ALL models (not just player ones, useful, innit?). This simply moves the entire model to the CFrame’s position coordinate (.P).
Alternatively, you could simply replace the CFrame with a Vector3 and remove the .P