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

How to change a bricks light color and color on touch?

Asked by 10 years ago

Hi! I am stuck on this. So the scenario is tht a "Brick" and "Pad" are both in a model. Then I used this code so when you touch the pad, the pointlight and brick will change to another color and when you stop touching it, it goes back to red. Can someone please help tell what is wrong?

local touching = false

script.Parent.Touched:connect(function(touch)
    if touch.Parent:findFirstChild("Humanoid") then
    touching = true
    script.Parent.Parent.Brick.Pointlight.color3.new(85, 255, 0)
    script.Parent.Parent.Brick.BrickColor = BrickColor.new("Bright green")
    end
end)

script.Parent.TouchEnded:connect(function(untouch)
    if untouch.Parent:findFirstChild("Humanoid") then
    touching = false
    script.Parent.Parent.Brick.Pointlight.color3.new(255, 0, 0)
    script.Parent.Parent.Brick.BrickColor = BrickColor.new("Bright red")
    end
end)

1 answer

Log in to vote
1
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
10 years ago

The property of a PointLight's color is "Color". It is a Color3 value. Also, make sure the path capitalization is correct. You put "Pointlight", but the default name is "PointLight". You may have changed it, but I just wanted to point it out.

local touching = false

script.Parent.Touched:connect(function(touch)
    if touch.Parent:findFirstChild("Humanoid") then
    touching = true
    script.Parent.Parent.Brick.Pointlight.Color = Color3.new(85, 255, 0)
    script.Parent.Parent.Brick.BrickColor = BrickColor.new("Bright green")
    end
end)

script.Parent.TouchEnded:connect(function(untouch)
    if untouch.Parent:findFirstChild("Humanoid") then
    touching = false
    script.Parent.Parent.Brick.Pointlight.Color = Color3.new(255, 0, 0)
    script.Parent.Parent.Brick.BrickColor = BrickColor.new("Bright red")
    end
end)

0
Color3 values range from 0 to 1, not 0 to 255 (which it appears as [incorrectly] in the Properties tab). Divide by 255 to get the proper values, e.g., 85 -> 0.333 or 85/255 BlueTaslem 18071 — 10y
Ad

Answer this question