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)
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)