The countdown loop im talking about is this and im not sure why it isnt working. The repeat until loop are for the crates to spawn until the round is over.
for i = GameLength, 0, -1 do
if i == 50 or i == 45 or i == 30 then
local crate = game.ReplicatedStorage.WoodCrate:Clone()
crate.Parent = workspace
crate:SetPrimaryPartCFrame(CFrame.new(840.125, 27.95, -195.455))
wait()
end
for x, player in pairs(plyrs) do
if player then
character = player.Character
if not character then
-- left the game
table.remove(plyrs,x)
else
if character:FindFirstChild("GameTag") then
-- They are still alive
print(player.Name.. "is still in the game")
else
table.remove(plyrs, x)
print(player.Name.. "has been removed from the game")
end
end
else
table.remove(plyrs,x)
print(player.Name.. "has been removed from the game")
end
end
Status.Value = "There are "..i.. " seconds remaining, and ".. #plyrs.. "players left"
if #plyrs == 1 then
-- Last person standing
Status.Value = "The winner is "..plyrs[1].Name
plyrs[1].leaderstats.Cash.Value = plyrs[1].leaderstats.Cash.Value + reward
break
elseif i == 0 then
Status.Value = "Time's up!"
break
end
wait(1)
end
Here's the rest of the script
local rs = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local MapsFolder = ServerStorage:WaitForChild("maps")
local Status = rs:WaitForChild("Status")
local GameLength = 50
local reward = 25
-- Game Loop
while true do
Status.Value = "Waiting for enough players"
repeat wait() until game.Players.NumPlayers >= 2
Status.Value = "Intermission"
wait(10)
local plyrs = {}
for i, player in pairs(game.Players:GetPlayers()) do
if player then
table.insert(plyrs, player) -- Add each players to the table
end
end
wait(2)
local availableMaps = MapsFolder:GetChildren()
local chosenMap = availableMaps[math.random(1, #availableMaps)]
Status.Value = chosenMap.Name.." Chosen!"
local mapCloned = chosenMap:Clone()
mapCloned.Parent = workspace
wait(5)
-- Teleport players
local spawnPoints = mapCloned:FindFirstChild("SpawnPoints")
local availableSpawnPoints = spawnPoints:GetChildren()
for i, player in pairs(plyrs) do
if player then
character = player.Character
if character then
-- teleport players
character:FindFirstChild("HumanoidRootPart").CFrame = availableSpawnPoints[1].CFrame
table.remove(availableSpawnPoints, 1)
-- Give Sword
local Sword = ServerStorage:FindFirstChild("Sword"):Clone()
Sword.Parent = player.Backpack
local GameTag = Instance.new("BoolValue")
GameTag.Name = "GameTag"
GameTag.Parent = player.Character
else
-- there is no character
if not player then
table.remove(plyrs, i)
end
end
end
end
Status.Value = "Get ready to play!"
for i = GameLength, 0, -1 do
for x, player in pairs(plyrs) do
if player then
character = player.Character
if not character then
-- left the game
table.remove(plyrs,x)
else
if character:FindFirstChild("GameTag") then
-- They are still alive
print(player.Name.. "is still in the game")
else
table.remove(plyrs, x)
print(player.Name.. "has been removed from the game")
end
end
else
table.remove(plyrs,x)
print(player.Name.. "has been removed from the game")
end
end
Status.Value = "There are "..i.. " seconds remaining, and ".. #plyrs.. "players left"
if #plyrs == 1 then
-- Last person standing
Status.Value = "The winner is "..plyrs[1].Name
plyrs[1].leaderstats.Cash.Value = plyrs[1].leaderstats.Cash.Value + reward
break
elseif i == 0 then
Status.Value = "Time's up!"
break
end
wait(1)
repeat wait(10) local crate = game.ReplicatedStorage.WoodCrate:Clone()
crate.Parent = workspace
crate:SetPrimaryPartCFrame(CFrame.new(840.125, 27.95, -195.455))
wait(2) until #plyrs == 1 and i == 0
end
print("End of game")
for i, player in pairs(game.Players:GetPlayers()) do
character = player.Character
if not character then
-- Ignore them
else
if character:FindFirstChild("GameTag") then
character.GameTag:Destroy()
end
if player.Backpack:FindFirstChild("Sword") then
player.Backpack.Sword:Destroy()
end
if character:FindFirstChild("Sword") then
character.Sword:Destroy()
end
end
player:LoadCharacter()
end
mapCloned:Destroy()
Status.Value = "Game ended!"
wait(2)
end
