Today I have have tried making a script for the Light which I am currently working on. Now I am hiving minor problems to this script on a Surface Gui.
So here is the script.
01 | script.Parent.MouseButton 1 Down:connect( function () |
02 | script.Parent.Parent.Parent.Parent.DynamicLight 1. PointLight.Enabled = true |
03 | script.Parent.Parent.Parent.Parent.DynamicLight 2. PointLight.Enabled = true |
04 | script.Parent.Parent.Parent.Parent.DynamicLight 3. PointLight.Enabled = true |
05 | script.Parent.Parent.Parent.Parent.DynamicLight 4. PointLight.Enabled = true |
06 | script.Parent.Parent.Parent.Parent.DynamicLight 5. PointLight.Enabled = true |
07 | script.Parent.Parent.Parent.Parent.DynamicLight 6. PointLight.Enabled = true |
08 | script.Parent.Parent.Parent.Parent.DynamicLight 7. PointLight.Enabled = true |
09 | script.Parent.Parent.Parent.Parent.DynamicLight 8. PointLight.Enabled = true |
10 | script.Parent.Parent.Parent.Parent.DynamicLight 9. PointLight.Enabled = true |
11 | script.Parent.Parent.Parent.Parent.DynamicLight 10. PointLight.Enabled = true |
12 | script.Parent.Parent.Parent.Parent.DynamicLight 11. PointLight.Enabled = true |
13 | script.Parent.Text = "Turn Off" -- I can't get this to work! |
14 | script.Parent.BackgroundColor 3 = { 170 , 0 , 0 } -- And also, this! |
15 | wait( 5 ) -- I want this to be changed to an function where you can turn it off instead of doing it on a timing. |
Line 14 is incorrect. Explained in comments:
1 | script.Parent.BackgroundColor 3 = Color 3. new( 170 , 0 , 0 ) --You didn't define the value, it is a Color3 value. |
Other than that, I can't really help with the changing of the Text, but I would assume it is a Hierarchy error. Make sure your Hierarchy is correct.
If you want a function to change it, rather than a loop, you can use the MouseButton1Click
event on a TextButton.
01 | local on = false |
02 |
03 | function onClicked() |
04 | if on = = false then |
05 | on = true |
06 | --add the turning on code |
07 | elseif on = = true then |
08 | on = false |
09 | -add the turning off code |
10 | end |
11 | end |
12 |
13 | script.Parent.MouseButton 1 Click:connect(onClicked) --This line is assuming the TextButton is the script's parent. |
Thanks for the script, but however the switching on works - but when you press the button again, it don't seem to be doing anything. Is there a glitch in the script or is it something to do with my model?
1 | function onClicked() |
2 |
3 |
4 | [ Your Script Here ] |
5 |
6 | script.Parent.MouseButton 1 Click:connect(onClicked) |
Try replacing the function/event with this, if that doesn't work, I have no clue.
(Unless you already did this step). Also, if you want to turn it off again than do another light switch I guess like: you can do visible = false after the script was executed and visible the light off switch gui.