I edited the code so that it only teleports one player, and it works! I’ll post both scripts below and add comments.
Teleports multiple players script:
local marketplaceService = game:GetService("MarketplaceService")
local tp = game:GetService("TeleportService")
local players = game:GetService("Players")
local part = script.Parent.Parent
local gameId = 0
local squad = {} -- A table of all the players in the who are participating
ready = false
local function addSquad(ppart)
local name = game.Players:FindFirstChild(ppart.Parent.Name) -- Finding the name of the player
if name then -- If it can retreive the name then it'll do the code below
if table.find(squad, name) == nil then -- Checks if the name already exists
table.insert(squad, name) -- Adds the code into the squad
end
for i, v in pairs(squad) do
print(squad[i])
end
end
end
function IsGameValid(id) -- Checks if the iD is a game iD
local isgame
local success,message = pcall(function()
local gameid = game:GetService('MarketplaceService'):GetProductInfo(id)
isgame = gameid.AssetTypeId == 9
end)
return success and isgame
end
function teleport(player)
local attempt = 0 -- Stores how many attempts it takes to get an iD that has the right requirements
part.Button:Play()
if ready == false then -- Checks if a game has already been chosen
script.Parent.Enabled = false -- Turns the prompt off
for i, v in pairs(game.Players:GetChildren()) do -- Tells everyplayer the text below
v.PlayerGui.Countdown.Text.Text = "Searching for a game (0 default places found)..."
end
while ready == false do -- Checks if a game has already been chosen
local gameId = Random.new():NextInteger(3000, 12000000000) -- Picks a random number
if IsGameValid(gameId) then -- Checks if the iD is a game iD
local isSuccessful, info = pcall(marketplaceService.GetProductInfo, marketplaceService, gameId)
if isSuccessful then
if ready == false then
if info.Name:match("'s Place") or info.Name:match("#") then -- Checks if the game is a default place
print("Insuffient detected")
attempt = attempt + 1
print(attempt)
if attempt == 1 then
for i, v in pairs(game.Players:GetChildren()) do
v.PlayerGui.Countdown.Text.Text = "Searching for a game (1 default place found)..."
end
else
for i, v in pairs(game.Players:GetChildren()) do
v.PlayerGui.Countdown.Text.Text = "Searching for a game (" .. attempt .. " default places found)..."
end
end
else
script.PlaceName.Value = info.Name -- Stores the info of the place name and iD
script.PlaceId.Value = gameId
ready = true -- Stops the game from finding a new game
end
end
end
end
end
end
for i, v in pairs(game.Players:GetChildren()) do
v.PlayerGui.Countdown.Text.Text = "Place found!"
end
wait(1)
if ready then
local timer = 5
repeat
if timer == 1 then
for i, v in pairs(game.Players:GetChildren()) do
v.PlayerGui.Countdown.Text.Text = "Teleporting to '" .. script.PlaceName.Value .. "' in 1 second..."
end
else
for i, v in pairs(game.Players:GetChildren()) do
v.PlayerGui.Countdown.Text.Text = "Teleporting to '" .. script.PlaceName.Value .. "' in " .. timer .. " seconds..."
end
end
script.Beep:Play()
wait(1)
timer = timer - 1
until timer < 0
game.Workspace.Closed.Transparency = 0
game.Workspace.Closed.CanCollide = true
script.Door:Play()
script.Charge:Play()
for i, v in pairs(squad) do -- Repeats the same amount of how many things that are in the squad
if game.Players:FindFirstChild(v.Name) then -- Checks if the names that are in the squad are also in game
local player = players:FindFirstChild(v.Name) -- Stores the name
tp:Teleport(script.PlaceId.Value, player) -- Teleports the player to the game
v:Destroy()
end
wait(5)
end -- All the code below are effects
wait()
repeat
wait(0.5)
until game.Workspace.Glow.Light.Brightness == 10
for i, v in pairs(squad) do
table.remove(squad, i)
end
ready = false
for i, v in pairs(game.Players:GetChildren()) do
v.PlayerGui.Countdown.Text.Text = ""
end
script.Parent.Enabled = true
end
end
script.Parent.Triggered:Connect(teleport)
part.Touched:Connect(addSquad)
Teleports only one player script:
local marketplaceService = game:GetService("MarketplaceService")
local tp = game:GetService("TeleportService")
local players = game:GetService("Players")
local part = script.Parent.Parent
local gameId = 0
local squad = {} -- A table of all the players in the who are participating
ready = false
local function addSquad(ppart)
local name = game.Players:FindFirstChild(ppart.Parent.Name) -- Finding the name of the player
if name then -- If it can retreive the name then it'll do the code below
if table.find(squad, name) == nil then -- Checks if the name already exists
table.insert(squad, name) -- Adds the code into the squad
end
for i, v in pairs(squad) do
print(squad[i])
end
end
end
function IsGameValid(id) -- Checks if the iD is a game iD
local isgame
local success,message = pcall(function()
local gameid = game:GetService('MarketplaceService'):GetProductInfo(id)
isgame = gameid.AssetTypeId == 9
end)
return success and isgame
end
function teleport(player)
local attempt = 0 -- Stores how many attempts it takes to get an iD that has the right requirements
part.Button:Play()
if ready == false then -- Checks if a game has already been chosen
script.Parent.Enabled = false -- Turns the prompt off
for i, v in pairs(game.Players:GetChildren()) do -- Tells everyplayer the text below
v.PlayerGui.Countdown.Text.Text = "Searching for a game (0 default places found)..."
end
while ready == false do -- Checks if a game has already been chosen
local gameId = Random.new():NextInteger(3000, 12000000000) -- Picks a random number
if IsGameValid(gameId) then -- Checks if the iD is a game iD
local isSuccessful, info = pcall(marketplaceService.GetProductInfo, marketplaceService, gameId)
if isSuccessful then
if ready == false then
if info.Name:match("'s Place") or info.Name:match("#") then -- Checks if the game is a default place
print("Insuffient detected")
attempt = attempt + 1
print(attempt)
if attempt == 1 then
for i, v in pairs(game.Players:GetChildren()) do
v.PlayerGui.Countdown.Text.Text = "Searching for a game (1 default place found)..."
end
else
for i, v in pairs(game.Players:GetChildren()) do
v.PlayerGui.Countdown.Text.Text = "Searching for a game (" .. attempt .. " default places found)..."
end
end
else
script.PlaceName.Value = info.Name -- Stores the info of the place name and iD
script.PlaceId.Value = gameId
ready = true -- Stops the game from finding a new game
end
end
end
end
end
end
for i, v in pairs(game.Players:GetChildren()) do
v.PlayerGui.Countdown.Text.Text = "Place found!"
end
wait(1)
if ready then
local timer = 5
repeat
if timer == 1 then
for i, v in pairs(game.Players:GetChildren()) do
v.PlayerGui.Countdown.Text.Text = "Teleporting to '" .. script.PlaceName.Value .. "' in 1 second..."
end
else
for i, v in pairs(game.Players:GetChildren()) do
v.PlayerGui.Countdown.Text.Text = "Teleporting to '" .. script.PlaceName.Value .. "' in " .. timer .. " seconds..."
end
end
script.Beep:Play()
wait(1)
timer = timer - 1
until timer < 0
game.Workspace.Closed.Transparency = 0
game.Workspace.Closed.CanCollide = true
script.Door:Play()
script.Charge:Play()
tp:Teleport(script.PlaceId.Value, player)
wait()
repeat
wait(0.5)
until game.Workspace.Glow.Light.Brightness == 10
for i, v in pairs(squad) do
table.remove(squad, i)
end
ready = false
for i, v in pairs(game.Players:GetChildren()) do
v.PlayerGui.Countdown.Text.Text = ""
end
script.Parent.Enabled = true
end
end
script.Parent.Triggered:Connect(teleport)
part.Touched:Connect(addSquad)
Edit: I tried editing the code so that it waits 5 seconds before teleporting players instead of teleporting players and then waiting 5 seconds but it doesn’t work, unfortunately. I’ll show you what the edited code looked like:
for i, v in pairs(squad) do -- Repeats the same amount of how many things that are in the squad
wait(5)
if game.Players:FindFirstChild(v.Name) then -- Checks if the names that are in the squad are also in game
local player = players:FindFirstChild(v.Name) -- Stores the name
tp:Teleport(script.PlaceId.Value, player) -- Teleports the player to the game
v:Destroy()
end