Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I change BackgroundColor3 using a GUI button?

Asked by 6 years ago

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 answer

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

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)
0
Hope this helped! SuperAndresZ_YT 202 — 6y
0
solved it, thank you. User#21139 0 — 6y
Ad

Answer this question