Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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)

1 comment

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

This discussion is preserved as it was. New answers, comments, and votes are closed.