Game jumps right to the end when it starts up

Every Time The Game Starts It just jumps To the end of the Game

The Game Should Last for 50 Seconds But lasts for 2 seconds
Heres the video
robloxapp-20201202-1838175.wmv (396.0 KB)

And Here is The Script

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)

end

1 Like

Do you have any game where we can see this code in action? Not uncopylocked, just the game itself cause there is a heap of code here.

Never mind, found the error. You instead want to do for i = 0, #GameLength do

(If the error still persists, I recommend rechecking variables and the output for anything that pops up.)

1 Like

That loop is correct. The loop he defined is saying count down from 50.

1 Like

Another problem When the player is killed They just stand there till the game ends

1 Like

That may have to do with respawn time on the spawnpoints, check the spawnpoints respawn time.

The spawn time is instant As said in the code

No no, I mean the physical spawns themselves.

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.)

1 Like

Here is a error For that
[ ServerScriptService.MainScript:90: attempt to get length of a number value]

True, that would be a better system then constantly getting the children out of the players themselves.

So I have To Make my plrs Table to Teams?
The Game Supports up to 14 players

1 Like

That is on my part, for i = 0, tostring(GameLength) do

Try this instead.

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

for i = 50, 0, -1 do

end

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.

The End just broke the whole game :frowning:

The End? What do you mean. Also, that was just an example of counting down.

You are right, I’m still fairly new to using for loops; so yeah.

Here is the link to the game So you guys or gals Can See whats happening
The Game Click Here

1 Like

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):