0

# I need help figuring out what I need to change in this on/off switch script?

Edited 7 months ago

I have a script that I'm using to make a working fireplace switch and it's almost complete with working switches. The only thing wrong with it is that clicking the first switch disables the particle emitters and clicking the second switch won't turn them back on but it still goes transparent like it should. I want to know what to add or change to the script below(I also added this same script to the second switch, but the values are reversed):

local switch

function onClick(playerWhoClicked)

switch = false

if switch == false then

script.Parent.Parent.FSwitchA.Transparency = 0

script.Parent.Parent.FSwitchB.Transparency = 1

script.Parent.Parent.Fire1.Firenum1.Enabled = false

script.Parent.Parent.Fire2.Firenum2.Enabled = false

script.Parent.Parent.Fire3.Firenum3.Enabled = false

script.Parent.Parent.FireSmoke.ChimneySmoke.Enabled = false

else

switch = true

if switch == true then

script.Parent.Parent.FSwitchA.Transparency = 1

script.Parent.Parent.FSwitchB.Transparency = 0

script.Parent.Parent.Fire1.Firenum1.Enabled = true

script.Parent.Parent.Fire2.Firenum2.Enabled = true

script.Parent.Parent.Fire3.Firenum3.Enabled = true

script.Parent.Parent.FireSmoke.ChimneySmoke.Enabled = true

    end
end
end


script.Parent.ClickDetector.MouseClick:Connect(onClick)

0
Sparks 534
7 months ago

The outer else-statement never runs. Every time .MouseClick is fired the switch is always set to false; it is thereby impossible to turn the fireplace back on.

local switch = false -- Initialize first use

function onClick(playerWhoClicked)

if switch == true then
switch = false -- Switch was on, now it is off and the fireplace is also off
script.Parent.Parent.FSwitchA.Transparency = 0
script.Parent.Parent.FSwitchB.Transparency = 1
script.Parent.Parent.Fire1.Firenum1.Enabled = false
script.Parent.Parent.Fire2.Firenum2.Enabled = false
script.Parent.Parent.Fire3.Firenum3.Enabled = false
script.Parent.Parent.FireSmoke.ChimneySmoke.Enabled = false

elseif switch == false then
switch = true -- Switch was off, now it is on and the fireplace is also on
script.Parent.Parent.FSwitchA.Transparency = 1
script.Parent.Parent.FSwitchB.Transparency = 0
script.Parent.Parent.Fire1.Firenum1.Enabled = true
script.Parent.Parent.Fire2.Firenum2.Enabled = true
script.Parent.Parent.Fire3.Firenum3.Enabled = true
script.Parent.Parent.FireSmoke.ChimneySmoke.Enabled = true
end
end

script.Parent.ClickDetector.MouseClick:Connect(onClick)

0
Thanks I got it to work just fine. KPNagai 4 — 7mo