Script doesnt work properly

So for some reason this piece of code work for one player but it kinda work for second but its dont make “NumbersClaimed” equal true for everything, only some of them.

Can you please help me out to figure why.

for _, numObj in ipairs(bn:GetChildren()) do
				if numObj.Value == randomNumber then
					for i,v in ipairs(allPlrs) do
						v:WaitForChild("NumbersClaimed"):FindFirstChild(numObj.Name).Value = true
					end
				end
			end
1 Like

Are you spawning in numObj.Name after you tell the script it iterate over bn’s children?? I’m not sure what the script is trying to do. Elaborate if you can.

(Edit: it’s not what I thought my I read it wrong)

2 Likes

Nitpick, don’t use :FindFirstChild(), there is no purpose because you’re indexing the result anyways, so if it doesn’t exist it will still throw an error.

For the issue, you’re really not giving enough information for us to solve the problem. What’s randomNumber?

How are you setting up randomNumber (could be the same num every time), allPlrs (maybe you’re setting that variable before other plrs are added), etc… I’m kinda lost on what the script is doing.

1 Like

so its generates random number after first player joins (i made a debounce so when another plr joins its not starting twice) so also i made a table of all players and when plr join it adds him to a table and i loop through this table to set NumbersClaimed varible inside plr to True

1 Like

Can you send the entire script, that would help.

Does the table of all plrs have any special information? Are you assigning a random num to every plr? I would use game.players:GetChildren() to see all current plrs… since you’ll also have to code in deleting them from the table if you don;t use that. Can you provide more of your script if possible?

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

local INTERMISSION_TIME = 20
local NUMBER_INTERVAL_TIME = 2
local NUMBERS_COUNT = 45

local deb = false

local allPlrs = {}

Players.PlayerAdded:Connect(function(player)
	
	table.insert(allPlrs, player)
	
	local function gameLoop()
	
	local bn = player:WaitForChild("BingoNums")
	local nc = player:WaitForChild("NumbersClaimed")
	
	if deb == false then
		
		deb = true

		for i = INTERMISSION_TIME, 1, -1 do
			print("Game starting in " .. i .. " seconds")
			wait(1)
		end

		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 = 1, NUMBERS_COUNT do
			print(allPlrs)
			local randomNumber
			repeat
				randomNumber = math.random(1, 75)
			until not nums[randomNumber]
			
			print(randomNumber)

			nums[randomNumber] = true

			ReplicatedStorage:WaitForChild("Num"):FireAllClients(randomNumber)

			wait(NUMBER_INTERVAL_TIME)

			

			for _, numObj in ipairs(bn:GetChildren()) do
				if numObj.Value == randomNumber then
					for i,v in ipairs(allPlrs) do
						v:WaitForChild("NumbersClaimed"):FindFirstChild(numObj.Name).Value = true
					end
				end
			end
		end
		print('game loop ended')
		deb = false
		gameLoop()
	end
	
	end
	gameLoop()
end)

P.S. for context i making a bingo game

(pls dont blame for this giant ugly table)

thats entire code i think this will help

Is this on the client, or the server? Also, you don’t need to store a table of all the players, to get the players you can use this:

Players:GetPlayers() -- an array of all the players in game.

i will try this maybe this help

Since I see this is the server, I think you might be setting the value of the number in the plr on the client… and that’s invisible to the server… where do you set the plr’s bingo num??

nah i checked this on server and its changing. The problem there that for second plr it changes not everything it suppose to

Tip, for that REALLY big table of false values, you should be able to use this instead:

table.create(75, false)

This only works for pass-by-value data.

1 Like

yooo its working but with some delay. But its finally works after 2 days of trying and this what matters

1 Like

Another thing, the way you get a random number right now is extremely unperformant (no offense). I’d recommend just inserting numbers into a table from 1 to 75, and then getting a random number from that table:

local index = math.random(#numList)
local number = numList[index]

table.remove(number, index)
1 Like

ye probably its the reason why script works with a delay

1 Like

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