Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I change BackgroundColor3 using a GUI button?

Script: https://gyazo.com/74b0f7bf6abec240bba18fa4bc0aa0ee

script.Parent.MouseButton1Click:connect(function() wait(1)

game.StarterGui.ScreenGui2.Frame.TextLabelA1.BackgroundColor3 = Color3.fromRGB(27,45,45)

end)

––––––––– I am trying to use a GUI button to change the BackgroundColor3, yet nothing happens. No errors, nothing. Just doesn't change color.

Example: https://gyazo.com/2e1fb6f8d9e8925145ceb750f80df06d

1 comment

1 answer

PLEASE READ ALL OF THIS TO KNOW WHAT'S GOING ON:

First of all:

  • StarterGui is just an object to STORE GUIs, when a player joins, the GUIs stored in StarterGui will be replicated to the player, where? in Player.PlayerGui.
  • Why the wait(1)? I'm not saying it's not okay, it's just that it's unnecessary in this case.
  • Please use :Connect() instead of :connect(); this one is deprecated.

These are things you need to know when using GUIs:

  • You should ONLY do stuff to GUIs using LocalScripts.
  • LocalScripts have access to game.Players.LocalPlayer, while the regular ones doesn't.

Now, the script you want is this:

script.Parent.MouseButton1Click:Connect(function()
	game.Players.LocalPlayer.PlayerGui.ScreenGui2.Frame.TextLabelA1.BackgroundColor3 = Color3.fromRGB(27, 45, 45)
end)

2 comments

0

Hope this helped!

0

solved it, thank you.

This discussion is preserved as it was. New answers, comments, and votes are closed.