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

Why is this not working? .-. Please help! :)

Asked by
Nidoxs 190
10 years ago
local isOn = true

function on()
 isOn = true
 script.Parent.PointLight.Enabled = true
script.Sound:Play()
script.Parent.Parent.Lights.Light.Pointlight.Enabled = false
script.Parent.Parent.Lights.Light2.Pointlight.Enabled = false
script.Parent.Parent.Lights.Light3.Pointlight.Enabled = false
script.Parent.Parent.Lights.Light4.Pointlight.Enabled = false
script.Parent.Parent.Lights.Light5.Pointlight.Enabled = false
script.Parent.Parent.Lights.Light6.Pointlight.Enabled = false
script.Parent.Parent.Lights.Light7.Pointlight.Enabled = false
script.Parent.Parent.Lights.Light8.Pointlight.Enabled = false
script.Parent.Parent.Lights.Light9.Pointlight.Enabled = false
end

function off()
 isOn = false
 script.Parent.PointLight.Enabled = false
script.Sound:Stop()
script.Parent.Parent.Lights.Light.Pointlight.Enabled = true
script.Parent.Parent.Lights.Light2.Pointlight.Enabled = true
script.Parent.Parent.Lights.Light3.Pointlight.Enabled = true
script.Parent.Parent.Lights.Light4.Pointlight.Enabled = true
script.Parent.Parent.Lights.Light5.Pointlight.Enabled = true
script.Parent.Parent.Lights.Light6.Pointlight.Enabled = true
script.Parent.Parent.Lights.Light7.Pointlight.Enabled = true
script.Parent.Parent.Lights.Light8.Pointlight.Enabled = true
script.Parent.Parent.Lights.Light9.Pointlight.Enabled = true
end

function onClicked()

 if isOn == true then off() else on() end

end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

on()

Please help! Here is the output : 21:29:19.030 - Script 'Workspace.TARDIS .Controls.Part.Light', Line 22 - global off 21:29:19.031 - Script 'Workspace.TARDIS.Controls.Part.Light', Line 35 21:29:19.032 - Stack End 21:29:19.033 - Disconnected event because of exception

Please give me a valid explanation of why the hell this doesn't work? :(((

0
Sorry beginner at scripting... Nidoxs 190 — 10y

1 answer

Log in to vote
0
Answered by 10 years ago
local isOn = true

function on()
 isOn = true
 script.Parent.PointLight.Enabled = true
script.Sound:Play()
script.Parent.Parent.Lights.Light.Pointlight.Enabled = false
script.Parent.Parent.Lights.Light2.Pointlight.Enabled = false
script.Parent.Parent.Lights.Light3.Pointlight.Enabled = false
script.Parent.Parent.Lights.Light4.Pointlight.Enabled = false
script.Parent.Parent.Lights.Light5.Pointlight.Enabled = false
script.Parent.Parent.Lights.Light6.Pointlight.Enabled = false
script.Parent.Parent.Lights.Light7.Pointlight.Enabled = false
script.Parent.Parent.Lights.Light8.Pointlight.Enabled = false
script.Parent.Parent.Lights.Light9.Pointlight.Enabled = false
end

function off()
 isOn = false
 script.Parent.PointLight.Enabled = false
script.Sound:Stop()
script.Parent.Parent.Lights.Light.Pointlight.Enabled = true
script.Parent.Parent.Lights.Light2.Pointlight.Enabled = true
script.Parent.Parent.Lights.Light3.Pointlight.Enabled = true
script.Parent.Parent.Lights.Light4.Pointlight.Enabled = true
script.Parent.Parent.Lights.Light5.Pointlight.Enabled = true
script.Parent.Parent.Lights.Light6.Pointlight.Enabled = true
script.Parent.Parent.Lights.Light7.Pointlight.Enabled = true
script.Parent.Parent.Lights.Light8.Pointlight.Enabled = true
script.Parent.Parent.Lights.Light9.Pointlight.Enabled = true
end

    function onClicked()

     if isOn == true then 
off()
    else 
on() 
end

end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

on()

I think it is because your if statement is on the same line as your else statement.

0
Also just to be safe you could add an extra elseif isOn == false then on() -- Note that elseif's do not require an end statement. @Line 37 legoguy939 418 — 10y
0
Thanks it worked! :) Much appreciated. Nidoxs 190 — 10y
0
No problem! legoguy939 418 — 10y
Ad

Answer this question