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

Why isn't this simple script working?

Asked by 8 years ago

I want clicking the play button in my game menu to change its background color to black and to change the background color of the other tabs in the menu to dark grey. I don't understand why this isn't working.

function onButtonClick()
    script.Parent.BackgroundColor3.r = 0
    script.Parent.BackgroundColor3.g = 0
    script.Parent.BackgroundColor3.b = 0
    script.Parent.Parent.Home.BackgroundColor3.r = 45
    script.Parent.Parent.Home.BackgroundColor3.g = 45
    script.Parent.Parent.Home.BackgroundColor3.b = 45
    script.Parent.Parent.Store.BackgroundColor3.r = 45
    script.Parent.Parent.Store.BackgroundColor3.g = 45
    script.Parent.Parent.Store.BackgroundColor3.b = 45
    script.Parent.Parent.Transfers.BackgroundColor3.r = 45
    script.Parent.Parent.Transfers.BackgroundColor3.g = 45
    script.Parent.Parent.Transfers.BackgroundColor3.b = 45
    script.Parent.Parent.Club.BackgroundColor3.r = 45
    script.Parent.Parent.Club.BackgroundColor3.g = 45
    script.Parent.Parent.Club.BackgroundColor3.b = 45
    script.Parent.Parent.Parent.PlayFrame.Visible = true
end

script.Parent.MouseButton1Click:connect(onButtonClick)

2 answers

Log in to vote
0
Answered by
Scriptree 125
8 years ago

You cannot change the red, green, or blue separately.

**Here is what you can use: **

script.Parent.Parent.Club.BackgroundColor3 = Color3.new(r,g,b) -- here, if it's set to (1,1,1) it would make the background white, (0,0,0) makes the background black
script.Parent.Parent.Club.BackgroundColor3 = Color3.new(r/255,g/255,b/255) -- here you can write the actual r,g,b color code

You can use the same method for everything else

Hope this helped :D

Ad
Log in to vote
0
Answered by 8 years ago

The r, g and b properties of a Color3 are read-only, meaning you can't edit them directly. You will need to use the Color3.new() constructor to change the colors of your GUI objects.

Also, if you're using the scale of 0 to 255, you need to divide each number you input by 255 as Color3s have a range of 0 to 1 on ROBLOX. However, this can be quite excessive, so I would personally write a function to return a Color3 which divides each r, g and b value by 255.

function Color3_255(r,g,b) --r, g and b are our argument variables for the function.
    return Color3.new(r/255,g/255,b/255) --Return this value to be used later on in the script
end

function onButtonClick()
    script.Parent.BackgroundColor3 = Color3.new() --No need to add numbers as Color3.new() sets each color value to 0.
    script.Parent.Parent.Home.BackgroundColor3 = Color3_255(45,45,45) --We can call our function, which will set the returned value of the function as the BackgroundColor3.
    script.Parent.Parent.Store.BackgroundColor3 = Color3_255(45,45,45)
    script.Parent.Parent.Transfers.BackgroundColor3 = Color3_255(45,45,45)
    script.Parent.Parent.Club.BackgroundColor3 = Color3_255(45,45,45)
    script.Parent.Parent.Parent.PlayFrame.Visible = true
end

script.Parent.MouseButton1Click:connect(onButtonClick)

I hope my answer helps you. If it did, be sure to accept it.

Answer this question