Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why doesn't this script toggle the fireplace--or do anything else at all?

Obviously this script is supposed to toggle a fireplace on or off, but it doesn't do, well, anything. It doesn't even give me any errors. My hierarchy is correct--I checked 4 times and rewrote it once too, just to make sure.

local fireplaceon = false

       func = function( p ) -- functions go HERE
            print(p.Name .. " toggled the fireplace!")
			if fireplaceon == false then
				fireplaceon = true
				game.Workspace.FaradayHouse.LivingRoom.GasFireplace.Fire.ParticleEmitter.Enabled = true
				game.Workspace.FaradayHouse.LivingRoom.GasFireplace.Fire.SpotLight.Enabled = true
			for i, v in pairs(game.Workspace.FaradayHouse.LivingRoom.GasFireplace.Chimney:GetChildren()) do
				if v.Name == "Smoke" then
					v.ParticleEmitter.Rate = 20
				end
			end
				
			end
			if fireplaceon == true then
				fireplaceon = false
				game.Workspace.FaradayHouse.LivingRoom.GasFireplace.Fire.ParticleEmitter.Enabled = false
				game.Workspace.FaradayHouse.LivingRoom.GasFireplace.Fire.SpotLight.Enabled = false
				for i, v in pairs(game.Workspace.FaradayHouse.LivingRoom.GasFireplace.Chimney:GetChildren()) do
					if v.Name == "Smoke" then
						v.ParticleEmitter.Rate = 0
					end
				end
				
			end
		end

1 answer

✓ Accepted answer

The primary issue here is that the instant the ParticleEmitter is being turned on, it's also being turned off. To find the reason behind this behavior, simply look at your conditionals and see that a simple 'elseif' can fix everything.

local fireplaceon = false
local fire = Workspace.FaradayHouse.LivingRoom.GasFireplace.Fire

function toggleFire(p)
  print(p.Name .. " toggled the fireplace!")
  if not fireplaceon then
    fire["ParticleEmitter"].Enabled = true
    fire["Spotlight"].Enabled = true
    for i, v in pairs(fire.Parent:GetChildren()) do
      if v.Name == "Smoke" then
      v.ParticleEmitter.Rate = 20
      end
    end
    fireplaceon = true
  elseif fireplaceon then
    fireplaceon = false
    fire["ParticleEmitter"].Enabled  = false
    fire["Spotlight"].Enabled  = false
    for i, v in pairs(fire.Parnet:GetChildren()) do
      if v.Name == "Smoke" then
      v.ParticleEmitter.Rate = 0
      end
    end
  end
end

This discussion is preserved as it was. New answers, comments, and votes are closed.