-
Im attempting to make a button change color when it is selected
-
The color of the button isn’t changing for certain buttons
-
I’ve put 2 prints that will activate if the conditions are met, and 2 warns if the conditions are not met
Code to edit the color (Server):
Events.Select_Button.OnServerEvent:Connect(function(plr, button: TextButton)
task.spawn(function()
for i, obj in pairs(Players:GetDescendants()) do
if obj:IsA("TextButton") or obj:IsA("ImageButton") then
if obj.Parent.Name == button.Parent.Name and not (button.Parent:IsA("SurfaceGui")) then
print(obj.Parent.Name .. " has passed (1) | Color = " .. tostring(button.Parent.BackgroundColor3))
if obj.Name == button.Name then
button.BackgroundColor3 = Color3.new(0, 0.227451, 0)
print(obj.Name .. " has passed (2) | Color = " .. tostring(button.BackgroundColor3))
else
button.BackgroundColor3 = Color3.new(0.188235, 0.188235, 0.188235)
warn(obj.Name .. " has not passed (2) | Color = " .. tostring(button.BackgroundColor3))
end
else
warn(obj.Parent.Name .. " has not passed (1) | Color = " .. tostring(button.Parent.BackgroundColor3))
end
end
end
end)
task.spawn(function()
for i, obj in pairs(game.StarterGui:GetDescendants()) do
if obj:IsA("TextButton") or obj:IsA("ImageButton") then
if obj.Parent.Name == button.Parent.Name then
print(obj.Parent.Name .. " has passed (1) | Color = " .. tostring(button.Parent.BackgroundColor3))
if obj.Name == button.Name then
button.BackgroundColor3 = Color3.new(0, 0.227451, 0)
print(obj.Name .. " has passed (2) | Color = " .. tostring(button.BackgroundColor3))
else
button.BackgroundColor3 = Color3.new(0.188235, 0.188235, 0.188235)
warn(obj.Name .. " has not passed (2) | Color = " .. tostring(button.BackgroundColor3))
end
else
warn(obj.Parent.Name .. " has not passed (1) | Color = " .. tostring(button.Parent.BackgroundColor3))
end
end
end
end)
end)
Code to fire the event (Local)
Events:WaitForChild("Select_Button"):FireServer(script.Parent)
Video: