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

Click Teleport not doing what it's supposed to?

Asked by 8 years ago

My script is in a part, and it is supposed to teleport the player that clicks the part to another part called Teleport. For some reason, it teleports every player in the server to Teleport. Can anyone help?

My script -

function onClicked()

local c = game.Players:GetChildren() 
for i = 1, #c do 
c[i].Character.Torso.CFrame = CFrame.new(script.Parent.Parent.Teleport.Position) 
end 

end 

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

1 answer

Log in to vote
0
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
8 years ago

Actually, it's doing exactly what it was made to do. On line 3, you're going through every player, rather than just the player who clicked it.

script.Parent.ClickDetector.MouseClick:connect(function(plr) -- It has a parameter of the player who clicked!
    plr.Character.Torso.CFrame = CFrame.new(script.Parent.Parent.Teleport.Position)
end)
Ad

Answer this question