Here is a script for a teleporter that I made:
local Teleport = workspace.TeleportPad
function Touch(hit)
if script.Parent.Locked == false and script.Parent.Parent:FindFirstChild("TeleportPad").Locked == false then script.Parent.Locked = time script.Parent.Parent:FindFirstChild("TeleportPad").Locked = true
local pos = script.Parent.Parent:FindFirstChild("TeleportPad")
hit.Parent:moveTo(workspace.TeleportPoint.Position) wait(1) script.Parent.Locked = false script.Parent.Parent:FindFirstChild("TeleportPad").Locked = false end end
script.Parent.Touched:Connect(Touch)
I want the teleporter to only work when at least 5 people (including both players and NPCs) step on it. What do I need to add to the script in order for that to happen?
you can make a table when a person touches it like this
script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then -- if there is a humanoid, its a player/character local plrs = {} local player = game.Players:GetPlayerFromCharacter(hit.Parent) table.insert(plrs,player) if #plrs >= 5 then for _,v in pairs(plrs) do game:GetService("TeleportService"):Teleport(yourplaceidhere,v) end end end end)
`
Hello there!
So to do this script, this is how I would do it.
local part= script.Parent local folderOfPlayers= part.Folder local amountofplayers= 0 local teleportPlace= 4918710826 --put your place id here local teleportService= game:GetService("TeleportService") part.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then local player= game.Players:GetPlayerFromCharacter(hit.Parent) if player then local playerName= hit.Parent.Name local findValue= folderOfPlayers:FindFirstChild(playerName) if not findValue then local value= Instance.new("StringValue") value.Name= playerName value.Parent=folderOfPlayers amountofplayers= amountofplayers + 1 if amountofplayers== 5 then for i,v in pairs(game.Players:GetChildren()) do local findPlayer= v.Name if folderOfPlayers:FindFirstChild(findPlayer) then teleportService:Teleport(teleportPlace, player) end end end end end end end)
This is quite a bit of code, so please, if this worked for you, tell me. If not, show me what error occurs.
Use a table
and count how many players are touching the teleporter, once the minimum is reached, teleport them
Use this:
local Teleport = workspace.TeleportPad local teleportService = game:GetService("TeleportService") local playerAmount = {} local placeId = 1234567890 local minPlayers = 5 function Touch(hit) if hit.Parent:FindFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(hit.Parent) ~= nil then local player = game.Players:GetPlayerFromCharacter(hit.Parent) if #playerAmount >= minPlayers then for i, v in pairs(playerAmount) do teleportService:Teleport(placeId, v) table.remove(playerAmount, i) end end end end) script.Parent.Touched:Connect(Touch)