Why does my for loop break early?

role.Limit = 8--(its in a module script)

for num=1, role.Limit do
	print(num, " ¦ num")
	print(role.Limit, " ¦ roleLimit")
	local rolechosen = false
	local chancenumber = math.random(1, 100)
	local chance = 0
	while rolechosen == false do
		for playerCount, player in pairs(Players:GetPlayers()) do
			if player:FindFirstChild("values"):FindFirstChild("chanceForKiller") then
				
			else
				continue
			end
			local playerKillerValue = player.values.chanceForKiller.Value * 100
			if chance <= chancenumber and chance + playerKillerValue >= chancenumber and _G.PlayerData[player.Name]["role"] == "Spectator" then
				_G.PlayerData[player.Name]["role"] = role.Name
				rolechosen = true
				roundStartEvent:FireClient(player, _G.PlayerData[player.Name]["role"], roleNumber)
				break
			end

			chance += playerKillerValue
		end
		task.wait()
	end
end

for some reason, the loop is breaking early when I dont want it to. (its breaking constantly on 5 when a local test of 8 people is done).

its fixed now, just had to adjust some of it.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.