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

Script teleports everyone when it should only tp me?

Asked by 4 years ago

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?

0
You are calling everyone in the game with game.Players:GetChildren() ChasingNachos 133 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago
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)
Ad

Answer this question