When 2 players load in; it says Times up or nobody won. Even though people are still alive.
Heres the Scirpt:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local MapsFolder = ServerStorage:WaitForChild("Maps")
local Status = ReplicatedStorage:WaitForChild("Status")
local GameLength = 30
while true do
Status.Value = "Waiting for 1 more player..."
repeat wait() until game.Players.NumPlayers >= 2
Status.Value = "Intermission"
wait(5)
Status.Value = "Game is Starting!"
local plrs = {}
for i, player in pairs (game.Players:GetPlayers()) do
if player then
table.insert(plrs,player)--Add each players into plrs table
end
end
wait(1)
local AvailableMaps = MapsFolder:GetChildren()
local ChosenMap = AvailableMaps[math.random(1,#AvailableMaps)]
Status.Value = "Choosing a Map..."
wait(3)
Status.Value = ChosenMap.Name.." Chosen"
wait(1)
local ClonedMap = ChosenMap:Clone()
ClonedMap.Parent = workspace
wait(1)
local SpawnPoints = ClonedMap:FindFirstChild("SpawnPoints")
if not SpawnPoints then
error("SpawnPoints not Found!")
end
pcall(function()
local AvailableSpawnPoints = SpawnPoints:GetChildren()
for i, player in pairs(plrs) do
if player then
character = player.Character
if character then
--Teleport Them
character:FindFirstChild("HumanoidRootPart").CFrame = AvailableSpawnPoints[1].CFrame + Vector3.new(0,8,0)
table.remove(AvailableSpawnPoints,1)
local startergun = game.ServerStorage.Guns:FindFirstChildOfClass("Tool"):Clone()
startergun.Parent = player.Backpack
game.Workspace:FindFirstChildOfClass("Player")
local GameTag = Instance.new("BoolValue")
GameTag.Name = "GameTag"
GameTag.Parent = player.Character
else
--There is no Character
if not player then
table.remove(plrs,i)
end
end
end
end
end)
Status.Value = "Get Ready to Play!"
wait(3)
for i = GameLength,0,-1 do
for x, player in pairs(plrs) do
if player then
character = player.Character
if not character then
--left the game
table.remove(plrs,x)
else
if character:FindFirstChild("GameTag") then
--They are still alive
print(player.Name.." is still in the game!")
else
--They are dead
table.remove(plrs,x)
end
end
else
table.remove(plrs,x)
print(player.Name.." has been Removed!")
end
end
Status.Value = "Free-For-All|Time:"..i.."|Players:"..#plrs..""
if #plrs == 1 then
Status.Value = "The Winner is "..plrs[1].Name
wait(2)
break
elseif #plrs == 0 then
Status.Value = "Nobody won!"
wait(3)
break
elseif i == 0 then
Status.Value = "Time's up!"
wait(3)
break
end
print("End of Game")
end
wait(1)
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
for _, tool in pairs(player.Backpack:GetChildren()) do
if tool:FindFirstChild("Price") then
tool:Remove()
end
end
for _, tool in pairs(character:GetChildren()) do
if tool:FindFirstChild("Price") then
tool:Remove()
end
end
end
player:LoadCharacter()
--print("Lol")
end
warn("Removed "..ClonedMap.Name.." Map. ")
ClonedMap:Remove()
wait(1)
Status.Value = "Game Ended"
end