Ad
Log in to vote
0

Why does the background color turn white instantly?

Asked by 4 months ago

Hello, every part of the script is responding well to eachother except the line where it changes the color to (30, 182, 20) which is a medium-dark green. Every time I run the script, it turns the button completely white, and the background color says (6500, 0, 0).

Player = game.Players.LocalPlayer --get the local player
color = script.Parent.Parent.Parent.Parent.Parent.Parent:WaitForChild("WhatColor")
script.Parent.MouseButton1Up:connect(function()


    if color.Value == "Green" then
        script.Parent.BackgroundColor3 = Color3.new(240, 0, 0)
        color.Value = "Red"
        script.Parent.Text = "Game Off"
        Player.Ingame.Value = false

    elseif color.Value == "Red" then

        script.Parent.BackgroundColor3 = Color3.new(30, 182, 20)
        color.Value = "Green"
        script.Parent.Text = "Game On"
        Player.Ingame.Value = true
    end





end)

1 answer

Log in to vote
0
Answered by 4 months ago
Player = game.Players.LocalPlayer --get the local player
color = script.Parent.Parent.Parent.Parent.Parent.Parent:WaitForChild("WhatColor")
script.Parent.MouseButton1Up:connect(function()
    if color.Value == "Green" then
        script.Parent.BackgroundColor3 = Color3.fromRGB(240, 0, 0)
        color.Value = "Red"
        script.Parent.Text = "Game Off"
        Player.Ingame.Value = false
    elseif color.Value == "Red" then
        script.Parent.BackgroundColor3 = Color3.fromRGB(30, 182, 20)
        color.Value = "Green"
        script.Parent.Text = "Game On"
        Player.Ingame.Value = true
    end
end)

OR

Player = game.Players.LocalPlayer --get the local player
color = script.Parent.Parent.Parent.Parent.Parent.Parent:WaitForChild("WhatColor")
script.Parent.MouseButton1Up:connect(function()
    if color.Value == "Green" then
        script.Parent.BackgroundColor3 = Color3.new(240/255, 0/255, 0/255)
        color.Value = "Red"
        script.Parent.Text = "Game Off"
        Player.Ingame.Value = false
    elseif color.Value == "Red" then
        script.Parent.BackgroundColor3 = Color3.new(30/255, 182/255, 20/255)
        color.Value = "Green"
        script.Parent.Text = "Game On"
        Player.Ingame.Value = true
    end
end)

Either method above works, it gets the exact color value that you specify.

0
use color3.fromRGB it's faster cuz you don't need to use math to put parameters in hiimgoodpack 1599 — 4mo
0
use local variables hiimgoodpack 1599 — 4mo
Ad

Answer this question



Ad