Answered by
5 years ago Edited 5 years ago
This should teleport a certain amount of players before you want the game to stop teleporting players. Also, the :MoveTo() method you used is depreciated so I used the non deprecated way of doing it. I was just assuming from your code that this is what you wanted to do, if you want the script to do anything else, please say so.
01 | local teleportTo = game.Workspace.Part |
02 | local numTeleportedPlayers = 0 |
03 | local canTeleport = true |
04 | PLAYERS_TELEPORTED_LIMIT = 2 ; |
06 | function OnTouched(part) |
10 | if (part.Parent:FindFirstChild( "HumanoidRootPart" ) and canTeleport = = true ) then |
11 | part.Parent.HumanoidRootPart.CFrame = CFrame.new(teleportTo.Position) |
13 | numTeleportedPlayers = numTeleportedPlayers + 1 |
16 | if numTeleportedPlayers > PLAYERS_TELEPORTED_LIMIT then |
18 | wait( 10 ) canteleport = true |
21 | script.Parent.Touched:connect(OnTouched) |
The script currently only checks if the number of players does teleported is too high, it does not check if the player uses the teleporter twice, but it can.
just change 'numTeleportedPlayers' to "teleportedPlayers = {}" and whenever a player teleports, add them to the table by using:
1 | table.insert(teleportedPlayers, part.Parent.Name) |
see if the player trying to be teleported has already teleported by adding a check to the following line:
1 | if (part.Parent:FindFirstChild( "HumanoidRootPart" ) and canTeleport = = true and not teleportingPlayers [ part.Parent.Name ] ) then |