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

How do I get this Light script to work? (UNSOLVED)

Asked by 10 years ago

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.


script.Parent.MouseButton1Down:connect(function() script.Parent.Parent.Parent.Parent.DynamicLight1.PointLight.Enabled = true script.Parent.Parent.Parent.Parent.DynamicLight2.PointLight.Enabled = true script.Parent.Parent.Parent.Parent.DynamicLight3.PointLight.Enabled = true script.Parent.Parent.Parent.Parent.DynamicLight4.PointLight.Enabled = true script.Parent.Parent.Parent.Parent.DynamicLight5.PointLight.Enabled = true script.Parent.Parent.Parent.Parent.DynamicLight6.PointLight.Enabled = true script.Parent.Parent.Parent.Parent.DynamicLight7.PointLight.Enabled = true script.Parent.Parent.Parent.Parent.DynamicLight8.PointLight.Enabled = true script.Parent.Parent.Parent.Parent.DynamicLight9.PointLight.Enabled = true script.Parent.Parent.Parent.Parent.DynamicLight10.PointLight.Enabled = true script.Parent.Parent.Parent.Parent.DynamicLight11.PointLight.Enabled = true script.Parent.Text = "Turn Off" -- I can't get this to work! script.Parent.BackgroundColor3 = {170,0,0} -- And also, this! wait(5) -- I want this to be changed to an function where you can turn it off instead of doing it on a timing. script.Parent.Parent.Parent.Parent.DynamicLight1.PointLight.Enabled = false script.Parent.Parent.Parent.Parent.DynamicLight2.PointLight.Enabled = false script.Parent.Parent.Parent.Parent.DynamicLight3.PointLight.Enabled = false script.Parent.Parent.Parent.Parent.DynamicLight4.PointLight.Enabled = false script.Parent.Parent.Parent.Parent.DynamicLight5.PointLight.Enabled = false script.Parent.Parent.Parent.Parent.DynamicLight6.PointLight.Enabled = false script.Parent.Parent.Parent.Parent.DynamicLight7.PointLight.Enabled = false script.Parent.Parent.Parent.Parent.DynamicLight8.PointLight.Enabled = false script.Parent.Parent.Parent.Parent.DynamicLight9.PointLight.Enabled = false script.Parent.Parent.Parent.Parent.DynamicLight10.PointLight.Enabled = false script.Parent.Parent.Parent.Parent.DynamicLight11.PointLight.Enabled = false script.Parent.Text = "Turn On" -- I can't get this to work! script.Parent.BackgroundColor3 = {0,85,0} -- And also, this! end) -- The script works, but there is problems where I put the "--" in.
0
I'd be glad to help but I have no clue what the parent of your script is. It might be good idea to define this to use or we can't really help Bman8765 270 — 10y
0
You also might want to consider adding your values to a table... Tortelloni 315 — 10y

3 answers

Log in to vote
0
Answered by 10 years ago

Line 14 is incorrect. Explained in comments:

script.Parent.BackgroundColor3 = Color3.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.

local on = false

function onClicked()
    if on == false then
        on = true
        --add the turning on code
    elseif on == true then
        on = false
        -add the turning off code
    end
end

script.Parent.MouseButton1Click:connect(onClicked) --This line is assuming the TextButton is the script's parent.
Ad
Log in to vote
0
Answered by 10 years ago

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?

Log in to vote
0
Answered by 10 years ago
function onClicked()


[Your Script Here]

script.Parent.MouseButton1Click: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.

Answer this question