Help with looping through players

So i am making a minigames game, similiar to epic minigames, and when a player spawns in, they are given a variable named ‘hasdied’. It does the opposite of what its name is and if it is true then it means that the player is in fact alive

while loop == true do
local numplayers = #Players:GetPlayers()
	amountplay = 0
	numhasnotdied = 0
	local winnername = ReplicatedStorage.winnername
	local winnericon = ReplicatedStorage.winnericon
	for _, player in Players:GetPlayers() do
		if player.hasdied.Value == false then
			amountplay += 1
		elseif player.hasdied.Value == true then
			numhasnotdied += 1
		end
	end


	if numhasnotdied == 1 then
		loop = false
		print('finish')
		local music = SoundService['win music']
		music:play()
		wait(4)
		local function reloadPlayer(player)
			local character = player.Character
			local humanoid = character:FindFirstChildOfClass("Humanoid")    
			if humanoid then
			humanoid.Health = 0  
			end
		end
		for _, player in Players:GetPlayers() do
			if player.Character.hasdied.Value == true then
				ReplicatedStorage.winnername.Value = player.Name
				ReplicatedStorage.winnericon.Value = player.UserId
			end
			reloadPlayer(player)
		end
		
		ReplicatedStorage.roundend:FireAllClients()
		workspace.game3.Parent = servstore
	end
	wait(0.2)
end

Ive got this script but it doesnt quite work for some reason, can anyone help?

That’s because once the round ends, the loop essentially just ends.

i should have been more specific. I want the round to end after only one player is left. However it doesnt

The problem here is that numhasnotdied will never reach one, as it is always being incremented and there is no code to subtract anything from it when the player dies. I would rework your code here a little bit to this:

local players = Players:GetPlayers()
local aliveplayers = {}
for i,player in pairs(players) do 
   table. Insert(aliveplayers,player)
end
while loop == true do
	amountplay = 0
	numhasnotdied = 0
	local winnername = ReplicatedStorage.winnername
	local winnericon = ReplicatedStorage.winnericon
	for _, player in players do
		if player.hasdied.Value == false then
			amountplay += 1
            table.remove(aliveplayers, table.find(aliveplayers, player)
		elseif player.hasdied.Value == true then
			numhasnotdied += 1
		end
	end


	if #aliveplayers == 1 then 
		loop = false
		print('finish')
		local music = SoundService['win music']
		music:play()
		wait(4)
		local function reloadPlayer(player)
			local character = player.Character
			local humanoid = character:FindFirstChildOfClass("Humanoid")    
			if humanoid then
			humanoid.Health = 0  
			end
		end
		for _, player in Players:GetPlayers() do
			if player.Character.hasdied.Value == true then
				ReplicatedStorage.winnername.Value = player.Name
				ReplicatedStorage.winnericon.Value = player.UserId
			end
			reloadPlayer(player)
		end
		
		ReplicatedStorage.roundend:FireAllClients()
		workspace.game3.Parent = servstore
	end
	wait(0.2)
end

I made it as similar to your original code as possible, even though I do not understand some parts of it. I would highly recommend you to clean up your code a bit as it’s a lil bit unreadable now

It never even reachers there as numhasnotdied will never be 1

the idea of this is right but apparently bind to action or something. The actual error is Cannot bind to action DataModel:Standalone, PluginId:ControlsEmulator, Category:Actions, ItemId:Toggle that does not exist if that means anything to you

Im even more stupid. I just misspelt something