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

Script teleports everyone when it should only tp me?

Hi I made a tp script. It should only tp the person who pressed the button but it teleports everyone in the game.

function onClicked()
local p = game.Players:GetChildren()
for i = 1, #p do
p[i].Character:MoveTo(Vector3.new(-1575.5, -18.75, -1088.5))
end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

How can I fix this?

1 comment

0

You are calling everyone in the game with game.Players:GetChildren()

1 answer

✓ Accepted answer
function onClicked(plr)
      local Character = game.Workspace:WaitForChild(plr.Name)
      if Character then
           Character:MoveTo(Vector3.new(-1575.5, -18.75, -1088.5))
     end
end

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

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