Problems with damage script

Hello, im trying to script a flamethrower and I have made a part which is welded to the gun mesh. I have a script that detects if the player touches that part and the flamethrower is shooting it damages the player. When I add an if statement to check if the fire particles from the flamethrower are turned on,the script breaks. Without the if statement it damages the player, but the problem is that it damages the player all the time. I have tried many ways of debugging it but I cannot find out how to fix it.
The script:

local part = script.Parent
local touching
local emitter = script.Parent.Parent.Shoot.ParticleEmitter

part.Touched:Connect(function(other)
    print ("Hi")
    local hum = other.Parent:FindFirstChild("Humanoid")
        if hum then
            if emitter.Enabled == true then
            print("No")
            touching = true
            while touching == true do
            print("Bye")
            hum:TakeDamage(3.5)
            wait(0.3)
            end
        end
    end
end)

part.TouchEnded:Connect(function()
    print("Ended")
    touching = false
end)

Thanks in advance.

I assume this is a server-side script. Are you enabling/disabling the emitter locally? Because if so, that’s probably why you’re having issues because it would only not emit particles for you and keep emitting particles for everyone else including the server which checks for it.

1 Like

You have to keep checking if the emitter is enabled every time you damage them again.
Because there’s two things that can kill the damage process:

victim player leaving the burn zone (handled that)

or assailant player letting off the gas (somewhere else in the script you’re refusing to show where mouse input it handled for on/ off yes? When button released touching = false)

1 Like