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.
local teleportTo = game.Workspace.Part
local numTeleportedPlayers = 0
local canTeleport = true
PLAYERS_TELEPORTED_LIMIT = 2;
function OnTouched(part)
if(part.Parent:FindFirstChild("HumanoidRootPart")and canTeleport == true)then
part.Parent.HumanoidRootPart.CFrame = CFrame.new(teleportTo.Position)
end
numTeleportedPlayers = numTeleportedPlayers + 1
end
if numTeleportedPlayers > PLAYERS_TELEPORTED_LIMIT then
canTeleport = false
wait(10) canteleport = true
end
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:
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:
if(part.Parent:FindFirstChild("HumanoidRootPart") and canTeleport == true and not teleportingPlayers[part.Parent.Name])then
2 comments
So you want to figure out how to stop teleporting players after a limit?
I'm working on a script for ^^^^ right now