ImageButton color change isn't working

Hey! I’m trying to change the background color of any of those image buttons to green (“Mint” as Roblox) and it works since I fire a remote client-server-client everytime I click on it, but when I try to do it directly server-client (using .CharacterAdded) it doesn’t works. The weird thing is that the remote is the same and it actually fires in both situations (I checked it multiple times in multiple ways, like printing), but in the second one (the wrong one) it actually doesn’t change the color (even though it prints as that color is the current one).

Here there is a screenshot so I can show you (I’m testing all of this printing in the cleaver knife image button, but the script is the same for all of those buttons), check output (it actually says “Mint”; any other printing at any part of the local script also is printed successfully):

Local Script (remote part):

remote.OnClientEvent:Connect(function(weapon) --weapon is the actual weapon which should be the same as the button name, so it works for every different script in every different button
	if weapon == button.Name then
		button.BackgroundColor3 = Color3.fromRGB(170, 255, 127)
		print(button.BackgroundColor3, button.BackgroundColor)
	else
		button.BackgroundColor3 = Color3.fromRGB(0,0,0)
	end
end)

Thank you for reading!

2 Likes

Playeradded often fires for everyone but the player that was added, maybe you could add a characteradded:wait(), that might run for the player

1 Like

But I’m saying it is actually firing for the player added, I can check that using prints.

Thank you for replying!

What happens if you add player.CharacterAdded:Wait() inside of the playeradded function, and put “player” inside of the function()?

1 Like

Are you sending a string through the remote event? If you are not you cannot compare an object with a string and have them equal. Maybe you can try weapon.Name?

1 Like

You need to debug more, try using a print statement under your else statement.

1 Like

This is a part of the server sided script, should I add a :Wait() after the CharacterAdded event?

game:GetService('Players').PlayerAdded:Connect(function(player)
	value.Parent = player
	player.CharacterAdded:Connect(function(character)
		player.RespawnLocation = game.Workspace.SpawnLocation
		weaponselection:FireClient(player,weaponselected)                   --weaponselection is the remote
	end)
end)

Thank you for replying!

Also did that, and only the prints inside the if statemente work (as it should).

Thank you for replying!

It is a string, so I can compare an object name to a string. Also, as I said, any prints inside the if statement work.

Thank you for replying!

Is the background of the image transparent?

1 Like

No, as you can see in the screenshot it is black, and the remote actually works, it just doesn’t work when called from CharacterAdded.

Thank you for replying!

Mind showing the button in explorer?

1 Like

Action is the local script, “Menu” (ScreenGui) is in StarterGui,

image

Thank you for replying!

I don’t think Color3.fromRGB() is needed. I’ve done a thing before and it did RGB just as Color3.new()

1 Like

.new() and .fromRGB() get completely different colours (even though I’d set its equivalent, the same still happens).

Thank you for replying!