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

Help with button script?

Hi,

I have this script and I want it to not only turn the light on and off but to change the brick colour. So when I press the button it turns the light on and changes the brick colour from Medium stone grey to Really red. When I click it again it turns the light off and changes the brick colour from Really red to Medium stone grey.

LP = script.Parent.Parent.SpotLight1.Light.SpotLight
btn = script.Parent.ClickDetector

function onClick()
if LP.Enabled == true then
LP.Enabled = false
else
LP.Enabled = true

end
end

btn.MouseClick:connect(onClick)


Thanks Kieran

1 answer

✓ Accepted answer

Here, let me help:

LP = script.Parent.Parent.SpotLight1.Light.SpotLight
btn = script.Parent.ClickDetector

function onClick()
	if LP.Enabled == true then
		LP.Enabled = false
		script.Parent.BrickColor = BrickColor.new("Medium stone grey") -- Not sure if s.p is the part, just change if needed
	else
		LP.Enabled = true
		script.Parent.BrickColor = BrickColor.new("Really red") -- Same here
	end
end

btn.MouseClick:connect(onClick)

1 comment

0

Thank you!

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