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

Is there another way to effectively rewrite this script?

Asked by 5 years ago
Edited by royaltoe 5 years ago

This is supposed to change Light (LightBulb) to yellow and then back to its original color (Institutional white) after one second. Is there another way to change it back to white after one second without saying Light.BrickColor = BrickColor.new("Institutional white") ?


Button = script.Parent Light = game.Workspace.Part2 Button.ClickDetector.MouseClick:connect(function() Light.BrickColor = BrickColor.new("New Yeller") wait(1) Light.BrickColor = BrickColor.new("Institutional white") end)
0
Can you use code block it's easier to read Vxpper 101 — 5y
0
Code looks fine to me. That's how I'd do it.  royaltoe 5144 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

Well, if you really dislike naming the colors, you can also use Color3.fromRGB(R,G,B) which if you have the Red Green and Blue value of your colors you can do this:

local Button = script.Parent -- local variables are better then global ones
local Light = game.Workspace.Part2

Button.ClickDetector.MouseClick:Connect(function() -- :Connect over :connect
    --Light.BrickColor = BrickColor.new("New Yeller")
    Light.Color = Color3.fromRGB(0,0,255) -- I think this is the color for yellow you can check
    wait(1)
    Light.Color = Color3.fromRGB(255,255,255) -- 90% sure this is white
    --Light.BrickColor = BrickColor.new("Institutional white") 


end)

This also gives you more variety over color rather then one of the pallets.

Hope this is what you were looking for.

0
Thanks, This was very helpful. FireCoolflame 21 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

I started working on an answer yesterday, but I ran out of time.

................

Like BlackOrange3343 said, you can't really shorten that. One solution, like BlackOrange3343 mentioned, is using the Color3.fromRBG(r, g, b) function with an rgb input. You can search up "color picker" on google to find rgb values. Another way is to name the given colors like this:

local button = script.Parent -- Local variables are better than global ones, and all variable names should start with a lowercase.
local light = game.Workspace.Part2 -- Consider changing the name "Part2" to something like "Light" so it's easier to understand
local yellow = Color3.fromRGB(255, 255, 0) -- The RGB value for Yellow is [255, 255, 0]
local white = Color3.fromRGB(255, 255, 255) -- The RGB value for White is [255, 255, 255]

local function colorChange() -- It's better to define functions with names.
    Light.Color = yellow
    -- Light.Color = Color3.fromRGB(255, 255, 0)
    -- Light.BrickColor = BrickColor.new("New Yeller")
    wait(1)
    Light.Color = white
    -- Light.Color = Color3.fromRGB(255, 255, 255) -- The RGB value for White is [255, 255, 255]
    -- Light.BrickColor = BrickColor.new("Institutional white") 
end

button.ClickDetector.MouseClick:Connect(colorChange) -- Use the :Connect function over :connect


Answer this question