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

Changing SpotLight colours/brightnesses with a script?

Asked by
Rothia 25
9 years ago

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.

0
Please put your code in appropriate code block. Goulstem 8144 — 9y
0
So the code only runs once? woodengop 1134 — 9y
0
The code doesn't run. At all. Rothia 25 — 9y
0
anything in the output? woodengop 1134 — 9y
View all comments (10 more)
0
I haven't used output, as I'm a scripting noob. Rothia 25 — 9y
0
I just tested it. Nothing appears. Rothia 25 — 9y
0
Is this a localscript or a script? woodengop 1134 — 9y
0
Script. Rothia 25 — 9y
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. Goulstem 8144 — 9y
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. Rothia 25 — 9y
0
Are trying to make the Spotlight change color everytime your click the button? UserOnly20Characters 890 — 9y
0
No - as the script states, pressing the button makes the SpotLight strobe, essentially. Rothia 25 — 9y
0
Lol, what do you mean by strobe? UserOnly20Characters 890 — 9y
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. Rothia 25 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

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

Ad

Answer this question