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

Why doesn't this script change the GUI Color?

Asked by 10 years ago

Inside of a Local Script, which is inside of a Text Button, I have the code:

if game.Players.LocalPlayer.leaderstats.Money.Value == 50 then
    script.Parent.BackgroundColor = BrickColor.new("Dark stone grey")
end

When the players money have reached 50 then the Text Button should become a grey color but doesn't. Why?

3 answers

Log in to vote
5
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

GUIs use BackgroundColor3 as the background color. It's a Color3 rather than a BrickColor:

script.Parent.BackgroundColor3 = BrickColor.new("Dark stone grey").Color
-- or something like
script.Parent.BackgroundColor3 = Color3.new(.4,.4,.4)

I originally assumed you already had the work in to do this check properly, however, I just realized you probably don't.

The code you have almost would work, but it has to be checked frequently (as you have it written, it will only check once -- when the player spawns).

We should also check that they have at least (>= larger than or equal to) 50, rather than (==) exactly 50.

while wait() do
    if game.Players.LocalPlayer.leaderstats.Money.Value >= 50 then
        script.Parent.BackgroundColor3 = Color3.new(.4,.4,.4)
    end
end
0
Blue nooo you beat me by one minute D: gg F_lipe 135 — 10y
0
It's not working still? Beachbum395 20 — 10y
0
I expanded upon my answer BlueTaslem 18071 — 10y
Ad
Log in to vote
0
Answered by
F_lipe 135
10 years ago

Try this:

if game.Players.LocalPlayer.leaderstats.Money.Value == 50 then
if script.Parent.BackgroundColor3 == (0, 0, 0) then-- Change this to the color that the Background Color is starting with
    script.Parent.BackgroundColor3 = Color3.new(0, 0, 0)--Change the 0's to your color the first zero is red, second 0 is green, and the third one is blue!
end
   end

If it doesn't work here I'll try doing something like it in a game of mine to see if I can find the problem.

Just shoot me a PM on roblox :)

0
It's not working still? Beachbum395 20 — 10y
1
Hmm let me take a look at it I'll edit it if I find an error I'm aware of how to fix :) F_lipe 135 — 10y
0
Could you tell me your output when the script is attempting to run. Also are you positive the parent of the script is the gui? F_lipe 135 — 10y
0
Sorry, it's a Text Label, not a Text Button. Beachbum395 20 — 10y
View all comments (3 more)
0
The script outputs no errors. The tree goes StarterGui > Shop (Screen Gui) > Money (Text Label) > Local Script Beachbum395 20 — 10y
0
I edited it a bit. F_lipe 135 — 10y
0
Also you could try the .Changed statement but I've never used it so you'll need to try out the wiki for that one. F_lipe 135 — 10y
Log in to vote
0
Answered by 4 years ago

Thx alot This worked :) "script.Parent.Parent.ObbyValue.BackgroundColor3 = Color3.new(.4,.4,.4)"

Answer this question