Script is not editing the background color of certain buttons

  1. Im attempting to make a button change color when it is selected

  2. The color of the button isn’t changing for certain buttons

  3. 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:

You should be changing the colour of the buttons with a local script, not a server script. I think the issue may be occuring because of this.

1 Like

I don’t think this is the issue because im looping through everyones playergui to change it, plus it wouldn’t make sense as only button 1 and 4 are changing colors

Heres a video of it happening too:

never mind i just realized i was changing the buttons color instead of the objects color