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

Changing SpotLight colours/brightnesses with a script?

I've been trying to modify a script that would give a lighting effect when a button is pushed, and instead of using the ambient (as code in the script was before), I'm trying to use SpotLights. I'm attempting this method instead of the ambient because it would give a stronger effect, but the effect only works when the script does. Instead of changing the respective colours and brightnesses of the SpotLights, they stay their natural colour. Once activated, the following lines of the script are supposed to run:

game.Workspace.SourceFour1.PanMe.TiltMe.Light.SpotLight.Color = Color3.new(1,1,1)
game.Workspace.SourceFour1.PanMe.TiltMe.Light.SpotLight.Brightness = 3
game.Workspace.SourceFour2.PanMe.TiltMe.Light.SpotLight.Color = Color3.new(1,0,0)
game.Workspace.SourceFour2.PanMe.TiltMe.Light.SpotLight.Brightness = 3
wait(.1)
game.Workspace.SourceFour1.PanMe.TiltMe.Light.SpotLight.Color = Color3.new(0,0,0)
game.Workspace.SourceFour1.PanMe.TiltMe.Light.SpotLight.Brightness = 0
game.Workspace.SourceFour2.PanMe.TiltMe.Light.SpotLight.Color = Color3.new(0,0,0)
game.Workspace.SourceFour2.PanMe.TiltMe.Light.SpotLight.Brightness = 0
wait(.1)

One the sequence noted above would be turned off, the script would return it to its natural colour and brightness, which is 1,1,1 and 3, respectively, though I need to make the sequence work before I can test that. I've tried taking the part named Light out of the model and leaving it in the Workspace in its lonesome, renaming it to prevent clashing with other parts called Light, but to no avail. I've also put a script directly into a SpotLight only to check and see if it could change its colours, which it did. Can someone help me?

[EDIT, 5/29] I have found out the reasoning behind its failure. The script was disabled.

14 comments

0

Please put your code in appropriate code block.

0

So the code only runs once?

0

The code doesn't run. At all.

0

anything in the output?

0

I haven't used output, as I'm a scripting noob.

0

I just tested it. Nothing appears.

0

Is this a localscript or a script?

0

Script.

0

Your interval, '.1', is quite small.. perhaps it's happening but you're not noticing? If there are no errors then you indexed everything correctly so it has to be an external error.

0

I've tested it on .2, and I've even clicked on the SpotLight as the script was supposedly running. Nothing was occurring with the SpotLight's properties.

0

Are trying to make the Spotlight change color everytime your click the button?

0

No - as the script states, pressing the button makes the SpotLight strobe, essentially.

0

Lol, what do you mean by strobe?

0

Rapidly flash on and off. Notice how there's two lights that are to strobe - one is white (1,1,1), and the other is red (1,0,0). They're supposed to rapidly turn on and off.

1 answer

You seem to forgot the basis of Color3.new! 'Any number in Color3.new must have a /255 right next to it for binary to read correctly' So in this case it would be...

game.Workspace.SourceFour1.PanMe.TiltMe.Light.SpotLight.Color = Color3.new(1/255,1/255,1/255)
game.Workspace.SourceFour1.PanMe.TiltMe.Light.SpotLight.Brightness = 3
game.Workspace.SourceFour2.PanMe.TiltMe.Light.SpotLight.Color = Color3.new(1/255,0/255,0/255)
game.Workspace.SourceFour2.PanMe.TiltMe.Light.SpotLight.Brightness = 3
wait(.1)
game.Workspace.SourceFour1.PanMe.TiltMe.Light.SpotLight.Color = Color3.new(0/255,0/255,0/255)
game.Workspace.SourceFour1.PanMe.TiltMe.Light.SpotLight.Brightness = 0
game.Workspace.SourceFour2.PanMe.TiltMe.Light.SpotLight.Color = Color3.new(0/255,0/255,0/255)
game.Workspace.SourceFour2.PanMe.TiltMe.Light.SpotLight.Brightness = 0
wait(.1)

Plus for a repeat just do

while true do
game.Workspace.SourceFour1.PanMe.TiltMe.Light.SpotLight.Color = Color3.new(1/255,1/255,1/255)
game.Workspace.SourceFour1.PanMe.TiltMe.Light.SpotLight.Brightness = 3
game.Workspace.SourceFour2.PanMe.TiltMe.Light.SpotLight.Color = Color3.new(1/255,0/255,0/255)
game.Workspace.SourceFour2.PanMe.TiltMe.Light.SpotLight.Brightness = 3
wait(.1)
game.Workspace.SourceFour1.PanMe.TiltMe.Light.SpotLight.Color = Color3.new(0/255,0/255,0/255)
game.Workspace.SourceFour1.PanMe.TiltMe.Light.SpotLight.Brightness = 0
game.Workspace.SourceFour2.PanMe.TiltMe.Light.SpotLight.Color = Color3.new(0/255,0/255,0/255)
game.Workspace.SourceFour2.PanMe.TiltMe.Light.SpotLight.Brightness = 0
wait(.1)
wait(.1)
end

Thanks! ~marcoantoniosantos3

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