Turning all buttons the color (Rebirth Help)

local function HasEnough(num, parent)
	local plr = script.Parent.Parent.Parent.Parent
	local ls = plr:WaitForChild("leaderstats")
	local coins = ls:WaitForChild("Clicks")
	local cost
	cost = script.Parent:WaitForChild(parent).Configuration.Cost.Value
	if coins.Value >= cost then
		script.Parent:WaitForChild(parent).TextButton.BackgroundColor3 = Color3.new(0.505882, 1, 0.45098)
		script.Parent:WaitForChild(parent).TextButton.BackgroundColor3 = Color3.new(1, 0.596078, 0.603922)
local function Rebirth(selected)
	local cost
	cost = script.Parent:WaitForChild(selected).Configuration.Cost.Value
for i, v in pairs(script.Parent:GetDescendants()) do
	if v:IsA("TextButton") then
			script.Parent:WaitForChild("Selected").Value = v.Parent.Name
			print("CUT G")
		while wait() do
			HasEnough(v.Name, v.Parent.Name)

I have a problem here. So basicly, I am trying to learn i, v in pairs and making a rebirth system. I want to make it so all buttons turn green or red. Problem here is ONLY ONE button is turning green or red. How do I fix?

try doing v:IsA(“TextButton”) instead of classname
EDIT: when u are sending the function HasEnough don’t put the name in it because that is a property

What would I use then? Plus I tried doing v:IsA(“TextButton”) and still does the same thing.

Just do when sending the function v.Parent
Edit: wait nvm I say that ur using waitforchild so u send the name

Infinite yield possible on ‘Players.FelixProfit.PlayerGui.Rebirth.ScrollingFrame:WaitForChild(“Instance”)’

When I do that

oh, just rap it into a pcall(function)

I have no idea how pcall works

all about pcalls

I will give you a brief about pcalls, when you have a wait for child it is always a good idea to use a call because if the player somehow does not load in the inf yield will never stop making the script run forever. A Pcall fixes that and when a player does not seem to load in the pcall would stop the waitforchild so no errors will happen.

1 Like