local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local ServerStorage = game:GetService(“ServerStorage”)
local MapsFolder = ServerStorage:WaitForChild(“Maps”)
local Status = ReplicatedStorage:WaitForChild(“Status”)
local GameLength = 50
local reward = 25
while true do
Status.Value = "Waiting for enough players"
repeat wait(1) until game.Players.NumPlayers >= 2
Status.Value = "Intermission"
wait(10)
local plrs = {}
for i, player in pairs(game.Players:GetPlayers()) do
if player then
table.insert(plrs,player)
end
end
wait(2)
local AvailableMaps = MapsFolder:GetChildren()
local ChosenMap = AvailableMaps[math.random(1,#AvailableMaps)]
Status.Value = ChosenMap.Name.." Chosen"
local CloneMap = ChosenMap:Clone()
CloneMap.Parent = workspace
local SpawnPoints = CloneMap:FindFirstChild("SpawnPoints")
if not SpawnPoints then
print("Error No SpawnPoints Found")
end
local AvailableSpawnPoints = SpawnPoints:GetChildren()
for i, player in pairs (plrs) do
if player then
character = player.Character
if character then
character:FindFirstChild("HumanoidRootPart").CFrame = AvailableSpawnPoints[1].CFrame
table.remove(AvailableSpawnPoints,1)
local Sword = ServerStorage.Sword:Clone()
Sword.Parent = player.Backpack
local GameTag = Instance.new("BoolValue")
GameTag.Name = "GameTag"
GameTag.Parent = player.Character
else
if not player then
table.remove(plrs,i)
end
end
end
end
Status.Value = "Get Ready To Play"
wait (2)
for i = GameLength,0 -1 do
for x, player in pairs(plrs) do
if player then
character = player.Character
if not character then
else
if character:FindFirstChild("GameTag") then
--Stil Alive
print(player.Name.."Is still In the Game!")
else
--There dead
table.remove(plrs,x)
print(player.Name.."Has Been Removed!")
end
end
else
table.remove(plrs,x)
print(player.Name.."Has Been Removed!")
end
end
Status.Value = "There are "..i.." Seconds Remaining, and "..#plrs.." players left"
if #plrs == 1 then
Status.Value = "The Winner Is "..plrs[1].Name
plrs[1].leaderstats.Bucks.Value = plrs[1].Leaderstats.Bucks.Value + reward
break
elseif #plrs == 0 then
Status.Value = "NoBody Won This Round"
break
elseif i == 0 then
Status.Value = "Time is Up!"
break
end
wait(1)
end
print("End of Game Cleaning Up!")
for i, player in pairs(game.Players:GetPlayers()) do
character = player.Character
if not character then
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
CloneMap:Destroy()
Status.Value = "Game Has Ended"
wait (2)
I think your problem lies in the plrs variable you defined. First off, to get a list of all players you can simply do:
local plrs = game:GetService("Players"):GetChildren()
As for why I point this out, it’s quite weird how you handle the players ingame. I think your issue resides in how you check each second whether or not the match has ended. Why not use the Teams service to do most of the work for you by assigning the competetors to a team and the dead in another?
(Edit: for below, the reason why that’s failing is because you can’t get the length of a number. Stick with what you had.)
No, tostring converts a number to a string value. Also, he is trying to count down. He is not trying to count up. For counting down, you do something like
Yes, all you will have to do is get the current players team, and if they have died while on the Playing team their team should be changed to the Lobby team.
It immediately ends 2 seconds after “Get ready to play”. This tells me this part is the issue (I am going to read it more in depth but here is where the issue is):