`local TeleTo = game.Workspace.oturak --What part you teleport to.
function OnTouched(part) part.Parent:MoveTo(TeleTo.Position) end
local teleportedplayers = 0
local canteleport = true if teleportedplayers > 0 then canteleport = false wait(10) canteleport = true end
script.Parent.Touched:connect(OnTouched)`
The max teleported players thing doesn't work what is my problem? thanks for help.
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 --What part you teleport to. Change this to whatever part you want to teleport to. local numTeleportedPlayers = 0 local canTeleport = true --boolean for if more players can / cannot be teleported PLAYERS_TELEPORTED_LIMIT = 2; -- specify the max number of players that can be teleported here function OnTouched(part) -- part.Parent:MoveTo(teleportTo.Position) --^^^^ is deprecated, use the below: 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
Put this script in ServerScriptService and change the "" in PART to the part's name.
cantp = true limit = 5 current = 0 teleto = game.Workspace.oturak PART = game.Workspace["Your Part's name / Part the player must touch(must be in workspace)"] game.Players.PlayerAdded:Connect(function(plr) PART.Touched:Connect(function(part) if part.Parent.Name == plr.Name then if current <= limit then if cantp then part.Parent.HumanoidRootPart.CFrame = teleto.CFrame + Vector3.new(0, 4, 0) current = current + 1 cantp = false wait(0.1) cantp = true else print("Not yet") end end end end) end)