Hello, I'm confused as to why the counter in my for loop is not being read, even though I have specified that the counter is y the script is not recognizing the y, please help!

When I load up the server with 2 players and the script runs it outputs this error:

11:40:00.506 - ServerScriptService.MainScript:112: attempt to concatenate global 'y' (a nil value)

Thank you for any help, the lines below are the lines that house the error.

for y, player in pairs(players) do
		if player then
			character = player.Character
			if not character then
				-- probably left
			else
				if character:FindFirstChild("GameTag") then
					--They are still alive
					print(player.Name.." is still in the game!")
				else
					--They are dead
					table.remove(players,x)
				end
			end
		else
			table.remove(players,x)
			print(player.Name.." has been removed!")
		end
	end
	
	Status.Value = "There are "..y.." seconds remaining, and "..#players.." players left"
	
	if #players == 1 then
		--Last person standing
		Status.Value = "The Winner is "..players[1].Name
		players[1].leaderstats.BattleCoins.Value = players[1].leaderstats.BattleCoins.Value + Reward
		break
	elseif #players == 0 then
		Status.Value = "Nobody won!"
		break
	elseif y == 0 then
		Status.Value = "Time up!"
		break
	end

5 comments

0

you have to change "y" to "i"

0

Nevermind, I just had to change around some values and it works fine now!

0

ok cool!

0

@TheRealPotatoChips The name of the variable does not matter. It can be named anything you want; it's just a variable.

0

insisii What did you change? I want to know