How do i make this for loop run many times?

i am a beginner developer, and i am scripting a title shop. however, the “color” button script wont seem to run more than once. ive tried to make another for loop that loops through this loop a certain amount of times, but it didnt work. im a beginner scripter, so i probably didnt even do it right. this is a local script. here is the script:

local titleScroll = player:WaitForChild("PlayerGui"):WaitForChild("TitlesGui"):WaitForChild("TitlesFrame"):WaitForChild("TitlesScroll")
local colorGui = player:WaitForChild("PlayerGui"):WaitForChild("ColorGui")
local colorButton = titleScroll:GetDescendants()

for _, descendant in pairs(colorButton) do
	if descendant:IsA("TextButton") and descendant.Name == "ColorButton" then
		descendant.MouseButton1Click:Connect(function()
			if true then
				titleScroll.Parent.Parent.Enabled = false
				colorGui.Enabled = true
			end
		end)
	end
end

please help

2 Likes

The power of WhileLoops, but do not overuse them, since it may cause lag. Good luck learning Lua!

2 Likes

the if true then is not needed…
What is the parent of the parent of titleScroll?

3 Likes

For loop only runs once Make something like that.

2 Likes

nvm it fixed itself somehow, mustve been some weird bug or smth

4 Likes

Yes yes, Roblox has their bug system. Good luck!! ;D

1 Like

As a tip: RunService is better than while loops as it is an event and does not need task.spawn()/coroutine.wrap()

RunService.RenderStepped:
RunService.Stepped:
RunService.Heartbeat:

2 Likes

Yes I know that, but Idk too. There are sometimes that we need While loops instead of run service.

But in this example, run service is better.

1 Like

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