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

Click teleport system teleports all in-game players rather than the one that clicked it. How to fix?

So I'm trying to make a set of teleports that work based on clicking a brick as opposed to touching one. So far with the help of a friend I've got it to work, but it actually teleports all the players in the game, as opposed to just the one player that clicked it. We've both tried varying ways so that it only teleports the one player, but then the teleport doesn't work at all.

function onClicked()

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

end 

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

For the record, "DoorExit1" is the name of the brick that everyone gets teleported to. I am aware "GetChildren" is the phrasing for getting all the players, but I am honestly struggling to make it work through other methods. Please help!

1 answer

✓ Accepted answer

ClickDetectors have a built-in parameter, being the player who clicked on the part. You can add that in to detect who clicked, and teleport them.

function onClicked(player)
	player.Character.Torso.CFrame = CFrame.new(script.Parent.Parent.DoorExit1.Position)
end 

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

2 comments

0

I tried something similar to that and it hadn't worked. But that does work. Thank you, it's a great help!

0

No problem.

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