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

How do I add the light colour to this?

Asked by
Danfly 5
10 years ago
local LightPart = workspace.Park
script.Parent.MouseButton1Click:connect(function()
    if LightPart:findFirstChild(LightPart.Name..'Light') then
        LightPart:findFirstChild(LightPart.Name..'Light'):Destroy()
        script.Parent.Text = 'Press to turn light on'
    else
        local light = Instance.new("PointLight", LightPart)
        light.Name = LightPart.Name..'Light'
        light.Range = 30
        script.Parent.Text = 'Press to turn light off'
    end
end)

When I turn the light on it is white. If I try going in "Play Solo" I turn the light on and edit the colour. When I turn it on and off again it goes back to white. Can someone suggestion something I need to add on the script and where to add it.

2 answers

Log in to vote
0
Answered by 10 years ago
local LightPart = workspace.Park
script.Parent.MouseButton1Click:connect(function()
    if LightPart:findFirstChild(LightPart.Name..'Light') then
        LightPart:findFirstChild(LightPart.Name..'Light'):Destroy()
        script.Parent.Text = 'Press to turn light on'
    else
        local light = Instance.new("PointLight", LightPart)
        light.Name = LightPart.Name..'Light'
        light.Range = 30
        script.Parent.Text = 'Press to turn light off'
    light.Color = Color3.new(r/255,g/255,b/255) --Change r to tone of red g to tone of green b to tone of blue
    end
end)

OR If you want to use a brickcolor do this

local LightPart = workspace.Park
script.Parent.MouseButton1Click:connect(function()
    if LightPart:findFirstChild(LightPart.Name..'Light') then
        LightPart:findFirstChild(LightPart.Name..'Light'):Destroy()
        script.Parent.Text = 'Press to turn light on'
    else
        local light = Instance.new("PointLight", LightPart)
        light.Name = LightPart.Name..'Light'
        light.Range = 30
        script.Parent.Text = 'Press to turn light off'
    light.Color = BrickColor.new("Bright blue").Color
    end
end)

There! It converts BrickColor into Color3

Ad
Log in to vote
0
Answered by
Noculus 25
10 years ago

Every time you run the script, you are deleting the old light and creating a new light. You have to re-enter in all the info of the light when creating a new one. Put in this after line 9...

light.Color = BrickColor.new("New yeller") --Or whatever you use to change the color
0
Wrong. Look at my answer to see what is wrong with yours fireboltofdeath 635 — 10y

Answer this question