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

Click Teleport not doing what it's supposed to?

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

✓ Accepted answer

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)

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