Script stops at some point

I was trying to make simple bingo game and this is script for random numbers that being given to players.

So the problem is that its not making all of that numbers you can see below “True” and just stops giving numbers at some point and i cant figure out why.

Can someone help me with that pls?

local Player = game:GetService('Players')
local repSt = game:GetService('ReplicatedStorage')

local INTERMISSION_TIME = 5
local NUMBER_INTERVAL_TIME = 0.1
local NUMBERS_COUNT = 45

Player.PlayerAdded:Connect(function(plr)
	
	for i = INTERMISSION_TIME, 0, -1 do
		wait(1)
		
		print('game starting in '..i..' seconds')
	end
	
	wait(1)
	
	local nums = {
		[0] = false,
		[1] = false,
		[2] = false,
		[3] = false,
		[4] = false,
		[5] = false,
		[6] = false,
		[7] = false,
		[8] = false,
		[9] = false,
		[10] = false,
		[11] = false,
		[12] = false,
		[13] = false,
		[14] = false,
		[15] = false,
		[16] = false,
		[17] = false,
		[18] = false,
		[19] = false,
		[20] = false,
		[21] = false,
		[22] = false,
		[23] = false,
		[24] = false,
		[25] = false,
		[26] = false,
		[27] = false,
		[28] = false,
		[29] = false,
		[30] = false,
		[31] = false,
		[32] = false,
		[33] = false,
		[34] = false,
		[35] = false,
		[36] = false,
		[37] = false,
		[38] = false,
		[39] = false,
		[40] = false,
		[41] = false,
		[42] = false,
		[43] = false,
		[44] = false,
		[45] = false,
		[46] = false,
		[47] = false,
		[48] = false,
		[49] = false,
		[50] = false,
		[51] = false,
		[52] = false,
		[53] = false,
		[54] = false,
		[55] = false,
		[56] = false,
		[57] = false,
		[58] = false,
		[59] = false,
		[60] = false,
		[61] = false,
		[62] = false,
		[63] = false,
		[64] = false,
		[65] = false,
		[66] = false,
		[67] = false,
		[68] = false,
		[69] = false,
		[70] = false,
		[71] = false,
		[72] = false,
		[73] = false,
		[74] = false,
		[75] = false,
	}

		
	for i,v in pairs(nums) do
		local ranNum = math.random(0,75)
		
		repSt:WaitForChild('Num'):FireAllClients(plr, ranNum)
		
		if nums[ranNum] == false then
			
			nums[ranNum] = true
		
			print(ranNum)
		
			wait(NUMBER_INTERVAL_TIME)
			
			
			local bn = plr:WaitForChild('BingoNums')
			local nc = plr:WaitForChild('NumbersClaimed')
			local gui = plr:WaitForChild('PlayerGui'):WaitForChild('BingoGui'):WaitForChild('Frame'):WaitForChild('MainFrame')
			
			for i,v in pairs(bn:GetChildren()) do
				if v.Value == ranNum then
					nc:FindFirstChild(v.Name).Value = true
				end
			end
			
			if nc.num1 == true and nc.num2 == true and nc.num3 == true and nc.num4 == true and nc.num5 == true then
				print('bingo')
			end
		else
			print('number already used')
		end
	end
	for i,v in pairs(nums) do
		if v == true then
			print('e')
		end
	end
end)

Well, first of all, your code is really unoptimized, reminds me of yandere dev code, second, im pretty sure its cause you’re using a for loop, when it finishes looping through, it stops.

2 Likes

It seems like the issue lies in how you’re checking and updating the nums table. The loop you have is intended to loop through all numbers and assign a random number to each. However, it seems you’re getting stuck because the loop is checking if a number has been used before firing the number to the clients. This approach can cause the loop to terminate early because it’s trying to assign already-used numbers.

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local INTERMISSION_TIME = 5
local NUMBER_INTERVAL_TIME = 0.1
local NUMBERS_COUNT = 75

Players.PlayerAdded:Connect(function(player)
    -- Wait for intermission time
    for i = INTERMISSION_TIME, 1, -1 do
        print("Game starting in " .. i .. " seconds")
        wait(1)
    end

    -- Initialize a table to keep track of generated numbers
    local nums = {
		[0] = false,
		[1] = false,
		[2] = false,
		[3] = false,
		[4] = false,
		[5] = false,
		[6] = false,
		[7] = false,
		[8] = false,
		[9] = false,
		[10] = false,
		[11] = false,
		[12] = false,
		[13] = false,
		[14] = false,
		[15] = false,
		[16] = false,
		[17] = false,
		[18] = false,
		[19] = false,
		[20] = false,
		[21] = false,
		[22] = false,
		[23] = false,
		[24] = false,
		[25] = false,
		[26] = false,
		[27] = false,
		[28] = false,
		[29] = false,
		[30] = false,
		[31] = false,
		[32] = false,
		[33] = false,
		[34] = false,
		[35] = false,
		[36] = false,
		[37] = false,
		[38] = false,
		[39] = false,
		[40] = false,
		[41] = false,
		[42] = false,
		[43] = false,
		[44] = false,
		[45] = false,
		[46] = false,
		[47] = false,
		[48] = false,
		[49] = false,
		[50] = false,
		[51] = false,
		[52] = false,
		[53] = false,
		[54] = false,
		[55] = false,
		[56] = false,
		[57] = false,
		[58] = false,
		[59] = false,
		[60] = false,
		[61] = false,
		[62] = false,
		[63] = false,
		[64] = false,
		[65] = false,
		[66] = false,
		[67] = false,
		[68] = false,
		[69] = false,
		[70] = false,
		[71] = false,
		[72] = false,
		[73] = false,
		[74] = false,
		[75] = false,
	}

    -- Generate random numbers
    for i = 1, NUMBERS_COUNT do
        local randomNumber
        repeat
            randomNumber = math.random(1, NUMBERS_COUNT)
        until not nums[randomNumber]

        -- Mark the number as generated
        nums[randomNumber] = true

        -- Fire the number to clients
        ReplicatedStorage:WaitForChild("Num"):FireAllClients(player, randomNumber)

        -- Wait for interval time
        wait(NUMBER_INTERVAL_TIME)

        -- Update player's numbers
        local bingoNumbers = player:WaitForChild("BingoNums")
        local numbersClaimed = player:WaitForChild("NumbersClaimed")
        local gui = player:WaitForChild("PlayerGui"):WaitForChild("BingoGui"):WaitForChild("Frame"):WaitForChild("MainFrame")

        for _, numObj in ipairs(bingoNumbers:GetChildren()) do
            if numObj.Value == randomNumber then
                numbersClaimed:FindFirstChild(numObj.Name).Value = true
                break  -- Break out of loop once number is found and updated
            end
        end

        -- Check for bingo
        local bingoAchieved = true
        for _, numObj in ipairs(numbersClaimed:GetChildren()) do
            if not numObj.Value then
                bingoAchieved = false
                break
            end
        end

        if bingoAchieved then
            print("Bingo!")
        end
    end
end)

1 Like

and instead of making that long table, you could use use a loop to define all the numbers, for example.

local nums = {}

for i = 0 , 75 do
  nums[i] = false
end
1 Like

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