Hello, I scripted a random map selector and round system with it and at first, it teleports one player into the map and says that they win and gives them the money, but then in the next round, it teleports one player but just says Round In Progress. I don't understand what is going on in the script. If you may please look at the script and tell me what is wrong, thank you.
Script:
local RepStorage = game:GetService("ReplicatedStorage")
local rEvent = RepStorage.RemoteEvents:WaitForChild("checkIf_inMainMenuOrLoading")
local IsVisorNot = nil
local InLobby = {}
local contestants = {}
local Status = game:GetService("ReplicatedStorage"):WaitForChild("Status")
local MapsFol = game:GetService("ReplicatedStorage"):WaitForChild("MapsStorage"):GetChildren()
local ClonedMapsFolder = Instance.new("Folder", workspace)
ClonedMapsFolder.Name = "ClonedMapsFolder"
-- Variables
rEvent.OnServerEvent:Connect(function(plr, value)
IsVisorNot = value
if IsVisorNot == false then
table.insert(InLobby, plr)
print(plr.Name.. " has joined the InLobby table")
end
end)
while true do
Status.Value = "Waiting For enough Players to Start the game!"
repeat wait(.5) until game.Players.NumPlayers >= 1
local rannum = math.random(1, #MapsFol)
for i = 10, 0, -1 do
Status.Value = "Intermission: "..i.." seconds left"
wait(1)
end
for pos, player in pairs(InLobby) do
if Status.Value == "Intermission: 0 seconds left" then
table.remove(InLobby, pos)
table.insert(contestants, player)
print(player.Name.." has joined the contestant table.")
end
end
for pos, plr in pairs(contestants) do
local char = plr.Character
local hum = char:FindFirstChild("Humanoid")
local humRootPart = char:FindFirstChild("HumanoidRootPart")
if Status.Value == "Intermission: 0 seconds left" then
local GameTag = Instance.new("BoolValue", plr)
GameTag.Name = "GameTag"
if char and plr and hum and humRootPart and plr:FindFirstChild("GameTag") then
if rannum == 1 then
local MapClone = game.ReplicatedStorage:WaitForChild("MapsStorage"):FindFirstChild("ForestMap"):Clone()
MapClone.Parent = workspace:FindFirstChild("ClonedMapsFolder")
local SpawnPoints = MapClone.HolysOne:FindFirstChild("Spawns")
for i = 5, 0, -1 do
Status.Value = "The Chosen Map is Holy's One"
wait(1)
if i == 0 then
break
end
end
if not SpawnPoints then
print("Server did not see any spawn points in Holys One!")
end
local ASPS = SpawnPoints:GetChildren()
if not plr then
table.remove(contestants, pos)
end
if char then
humRootPart.CFrame = ASPS[1].CFrame
table.remove(ASPS, 1)
end
elseif rannum == 2 then
local MapClone = game.ReplicatedStorage:WaitForChild("MapsStorage"):FindFirstChild("UnknownTerritory"):Clone()
MapClone.Parent = workspace:FindFirstChild("ClonedMapsFolder")
local SpawnPoints = MapClone.UnknownTerritory:FindFirstChild("Spawns")
for i = 5, 0, -1 do
Status.Value = "The Chosen Map is Unknown Territory"
wait(1)
if i == 0 then
break
end
end
if not SpawnPoints then
print("Server did not see any spawn points in Unknown Territory!")
end
local ASPS = SpawnPoints:GetChildren()
if not plr then
table.remove(contestants, pos)
end
if char then
humRootPart.CFrame = ASPS[1].CFrame
table.remove(ASPS, 1)
end
--elseif rannum == 3 then
--humRootPart.CFrame =
end
end
if #contestants >= 2 then
for i = 10, 0, -1 do
Status.Value = "Round In Progress: "..i.." seconds left"
wait(1)
if i == 0 then
break
end
end
elseif #contestants == 1 then
for i = 5, 0, -1 do
Status.Value = plr.Name.." has won the game! "..i
wait(1)
if i == 0 then
break
end
end
contestants[1].leaderstats.Scaxxe.Value = contestants[1].leaderstats.Scaxxe.Value + math.random(50, 150)
end
end
hum.Died:Connect(function()
if plr:FindFirstChild("GameTag") then
table.remove(contestants, pos)
table.insert(InLobby, plr)
plr.GameTag:Destroy()
end
end)
if Status.Value == plr.Name.." has won the game! 0" or "Round In Progress: 0 seconds left" then
for i, v in pairs(InLobby) do
if v:FindFirstChild("GameTag") then
v.GameTag:Destroy()
end
end
for i, v in pairs(contestants) do
if v:FindFirstChild("GameTag") then
v.GameTag:Destroy()
end
end
humRootPart.CFrame = workspace.SpawnLocation.CFrame * CFrame.new(0, 5, 0)
end
for _, v in pairs(ClonedMapsFolder:GetChildren()) do
if v then
v:Destroy()
end
end
end
end
game:GetService("Players").PlayerRemoving:Connect(function(plr)
for i, _ in pairs (game:GetService("Players"):GetPlayers()) do
table.remove(InLobby, i) table.remove(contestants, i)
print(plr.Name.." has been removed from the contestants or InLobby table")
end
end)
Thank you once again in advance!

2 comments
Is your script in Workspace or ServerScriptService? Bcz long time ago, I made a similar script but left it in the workspace, so it got executed for only one player until I realized I forgot to keep it in the ServerScriptService
My script is in ServerScriptService