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)
else
script.Parent:WaitForChild(parent).TextButton.BackgroundColor3 = Color3.new(1, 0.596078, 0.603922)
end
end
local function Rebirth(selected)
print(selected)
local cost
cost = script.Parent:WaitForChild(selected).Configuration.Cost.Value
print(cost)
end
for i, v in pairs(script.Parent:GetDescendants()) do
if v:IsA("TextButton") then
print(v.Name)
v.MouseButton1Click:Connect(function()
script.Parent:WaitForChild("Selected").Value = v.Parent.Name
Rebirth(script.Parent:WaitForChild("Selected").Value)
print("CUT G")
end)
while wait() do
HasEnough(v.Name, v.Parent.Name)
end
end
end
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?