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.

4 comments
both*
or maybe its beacuse there is not much to loop around at "script.Parent.Parent.Frame:GetChildren()"
I tried removing the debounce statement and any waits, but it is still only looping once. I also keep getting the error message Text is not a valid member of UIGridLayout "Players.Rayguyban2.PlayerGui.ScreenGui.Frame.Frame.UIGridLayout" and I don't know how to
ohhh ok, well its solved lool