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

How do I make a GUI button when toggled, it changes color?

Asked by 5 years ago
Edited 5 years ago

So I am trying to redo this script for a gui, and I wanted to add this feature where if you toggle the button it changes color. In this scenario, I wanted to specifically do; when its off, its (30,30,31) and when its on, its (255,0,0). However, I came into contact with this problem that after turning it off, the color is then brighter than the original. Heres the script:

local P = script.Parent.Parent.Parent.Parent.Parent.Name
local HLoc = game.Workspace:FindFirstChild(P)
HighVis = script.Parent.Parent.Parent.HighVis
LowVis = script.Parent.Parent.Parent.LowVis

function onClick(mouse)
    local Helmet = HLoc:findFirstChild("Face")
    if Helmet ~= nil and HighVis.Value==false and LowVis.Value==false then
        Helmet.Light.Bright.Enabled = true
        Helmet.glass.Transparency = 0
        Helmet.Light2.light.Enabled = true
        script.Parent.BackgroundColor3 = Color3.new(255,0,0)
    HighVis.Value = true
    elseif Helmet ~= nil and HighVis.Value==true and LowVis.Value==false then
        Helmet.Light.Bright.Enabled = false
        Helmet.glass.Transparency = 1
        Helmet.Light2.light.Enabled = false
        script.Parent.BackgroundColor3 = Color3.new(10,10,11)
    HighVis.Value = false
    end
end

script.Parent.MouseButton1Down:connect(onClick)

1 answer

Log in to vote
0
Answered by
Rheines 661 Moderation Voter
5 years ago

Color3.new()'s arguments require numbers that ranges between 0 and 1, so what you need to do is to divide every number inside it by 255.

local P = script.Parent.Parent.Parent.Parent.Parent.Name
local HLoc = game.Workspace:FindFirstChild(P)
HighVis = script.Parent.Parent.Parent.HighVis
LowVis = script.Parent.Parent.Parent.LowVis

function onClick(mouse)
    local Helmet = HLoc:findFirstChild("Face")
    if Helmet ~= nil and HighVis.Value==false and LowVis.Value==false then
        Helmet.Light.Bright.Enabled = true
        Helmet.glass.Transparency = 0
        Helmet.Light2.light.Enabled = true
        script.Parent.BackgroundColor3 = Color3.new(255/255,0/255,0/255)
    HighVis.Value = true
    elseif Helmet ~= nil and HighVis.Value==true and LowVis.Value==false then
        Helmet.Light.Bright.Enabled = false
        Helmet.glass.Transparency = 1
        Helmet.Light2.light.Enabled = false
        script.Parent.BackgroundColor3 = Color3.new(10/255,10/255,11/255)
    HighVis.Value = false
    end
end

script.Parent.MouseButton1Down:connect(onClick)

You can also use Color3.fromRGB(r,g,b) that takes any number from 0 to 255.

Ad

Answer this question