Not Completing the GameMode

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
1 Like

So after experimenting I think that the game loop is only running once. That’s the loop starting at line 87. I might be wrong though. I put a print(I) right after line 87 and it only printed 30. It should count down from 30. I will try to find a fix…
EDIT: Ok, so I reversed the for loop I mentioned above and it only looped once. (Btw I put a print(“Player Dead”) when it removes a player because they have no game tag.) But, it printed that I was dead but I added another print and it says it had tagged me as alive so I will try to figure it out some more. It might take a lot more time or someone more advanced than me. But, I will try some more…

EDIT 2: Welp, I’m stumpped… :frowning_face:

1 Like

Nice try helping… i still havent found a fix.

Not sure if this helps, but game.Players.NumPlayers is deprecated.

Could you see if you get any errors in Script Analysis? Does everything print in the output?

I took a glance over it and it looks like your for loop

for i = GameLength,0,-1 do 

section seems to be missing a wait(1) so it’s just immediately skipping to the end. Also I’d suggest simply moving the

print("End of Game")

out of the scope of said for loop or it’ll print End of Game quite a bit.

1 Like

in another game i have, NumPlayers works so

Thank you the wait fixed it all

You are just forgetting a wait() inside of the loop.

Yes, even though in my other game, i dont use a wait after gamelength, but afetr i added the
`

wait(1)

`
it works!

No problem, happy to help. If you ever have anymore issues pop by and see if I can give you a hand.

I had did that too but I was testing it in single player so it said I won… :see_no_evil: