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

Value Color Changing not working?

Asked by 8 years ago

The purpose of this script is for the block this script is in, if the value labeled resources, is 1000 it will be 1000, it will be 1 color, and if its 900 it will be another color, for some reason, i Don't get any errors, but the colors wont change. Please help me out! Thanks for reading.

if workspace.Resources.Value == 1000 then
script.Parent.BrickColor = BrickColor.new("Bright green")
elseif workspace.Resources.Value == 900 then
script.Parent.BrickColor = BrickColor.new("Br.yellowish green") 
end

1 answer

Log in to vote
1
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
8 years ago

Well, there are 2 ways you can solve your problem. By using a Changed event, or a loop. I'll show both. The reason yours doesn't work, is because it doesn't know when to check if the value is 1000 or 900!

Changed:

game.Workspace.Resources.Changed:connect(function()
    if game.Workspace.Resources.Value == 1000 then
        script.Parent.BrickColor = BrickColor.new("Bright green")
    elseif game.Workspace.Resources.Value == 900 then
        script.Parent.BrickColor = BrickColor.new("Br.yellowish green") -- Heh, I've never seen that. Make sure spelling is correct!
    end
end)

Loop:

while wait() do
    if game.Workspace.Resources.Value == 1000 then
        script.Parent.BrickColor = BrickColor.new("Bright green")
    elseif game.Workspace.Resources.Value == 900 then
        script.Parent.BrickColor = BrickColor.new("Br.yellowish green")
    end
end
0
Thanks for helping me! and for all your support :D! viralmoose 65 — 8y
0
No problem! Shawnyg 4330 — 8y
Ad

Answer this question