I was trying to make a game that when you click a button it gives you a random number based on your level which is the Output and you had to hit the goal from a random generated number, so I tried to do a in pairs loop to get all of the Outputs at once, but it only generated a number for one Output. I also printed the Value and Index for the loop but it printed one value out of all the Outputs I had, I also had a UI Grid Layout where all the Output labels are and it kept erroring, but I didn't know how to fix it. Here is the code I used -
local debounce = false -- This is a local script local ReplicatedStorage = game:GetService("ReplicatedStorage") local RemoteEvent = ReplicatedStorage["1Level"] script.Parent.MouseButton1Down:connect(function() local player = game.Players.LocalPlayer for i, v in pairs(script.Parent.Parent.Frame:GetChildren()) do local LevelV = game.Players[player.Name].leaderstats.Level.Value local randomizer = math.random(1, LevelV*2+2) local TimeV = .1 print(v.Text) print(i) if not debounce then v.Text = randomizer if v.Text == script.Parent.Parent.Goal.Text then v.BackgroundColor3 = Color3.fromRGB(0, 255, 0) TimeV = 2.6 debounce = true wait(TimeV) TimeV = 0.1 debounce = false wait(2.5) RemoteEvent:FireServer() v.BackgroundColor3 = Color3.fromRGB(255, 255, 255) else v.BackgroundColor3 = Color3.fromRGB(255, 255, 255) debounce = true wait(TimeV) TimeV = 0.1 debounce = false wait(.1) end end end end)
Also if your wondering what the RemoteEvent it's to make the player level up 1.
you are looping through the descendants of script.Parent.Parent.Frame. what I get from the information you have provided is that inside the Frame there is a UIGridLayout. when you start looping through frames children it gets to UIGridLayout and then trys to make UIGridLayout aka v = randomizer like on line 20 (v.Text = randomizer). UIGridLayout does not have text so the script breaks and stops running.
maybe its the cause of your debounce or if statement, to check this remove bot of those(for now) and try if it loops a bunch of times