Make FlameThrower play a sound when Throwing flames

Im making a flamethrower for my game, but im stuck on making it play a sound when I shoot it.

I have the sounds located in the handle with the name loop.

I tried doing

function OnActivated()
     Handle.Loop:Play()

But it broke the gun

This is the script

Tool = script.Parent

activated = 0
deactivated = 0

function OnActivated()
	script.Parent.Configurations.Active.Value = true
	activated = os.time()
	Tool.Shoot.Fire.Enabled = true
	Tool.Shoot.Smoke.Enabled = true
	for i = 1,10 do
	Tool.Shoot.Transparency = 1-i/10
	wait()
		
	end
end

function OnDeactivated()
	script.Parent.Configurations.Active.Value = false
	deactivated = os.time()
	local totaltimeactive = deactivated-activated
	if totaltimeactive < 1 then
		totaltimeactive = 1
	end
	Tool.Shoot.Fire.Enabled = false
	Tool.Shoot.Smoke.Enabled = false
	
	print(totaltimeactive/2)
	Tool.Shoot.AfterSmoke.Enabled = true
	wait(totaltimeactive/2)
	Tool.Shoot.AfterSmoke.Enabled = false
	for i = 1,100 do
	Tool.Shoot.Transparency = i/100
	wait()
	end
end



Tool.Activated:connect(OnActivated)
Tool.Deactivated:connect(OnDeactivated)

Try setting Looped in the properties to true.
If doing the Handle.Loop:Play() broke your gun it means something else you did was wrong because playing a sound shouldn’t be able to break anything. Unless there’s something in the handle called loop that isn’t a sound so it errors and breaks the gun. All you have to do is check the console for any errors.

Looped Is the Name of the sound. and its already Looped in properties, Its just when i fire my gun it dont play the sound

Try renaming the Sound just for testing. I’d also recommend stopping the sound if you stopped shooting flames. May you could tell us if there are any errors in the output if activated?
Try this and firstly locate the Handle instance:

local Tool = script.Parent
local Handle = ?
local LoopSound = Handle.Loop
local activated = 0
local deactivated = 0

function OnActivated()
LoopSound:Play()
	script.Parent.Configurations.Active.Value = true
	activated = os.time()
	Tool.Shoot.Fire.Enabled = true
	Tool.Shoot.Smoke.Enabled = true
	for i = 1,10 do
	Tool.Shoot.Transparency = 1-i/10
	wait()
		
	end
end

function OnDeactivated()
LoopSound:Stop()
	script.Parent.Configurations.Active.Value = false
	deactivated = os.time()
	local totaltimeactive = deactivated-activated
	if totaltimeactive < 1 then
		totaltimeactive = 1
	end
	Tool.Shoot.Fire.Enabled = false
	Tool.Shoot.Smoke.Enabled = false
	
	print(totaltimeactive/2)
	Tool.Shoot.AfterSmoke.Enabled = true
	wait(totaltimeactive/2)
	Tool.Shoot.AfterSmoke.Enabled = false
	for i = 1,100 do
	Tool.Shoot.Transparency = i/100
	wait()
	end
end



Tool.Activated:connect(OnActivated)
Tool.Deactivated:connect(OnDeactivated)

I Tried what u gaveme, it didnt work and my flamethrower stop shooting fire , so i changed the audio name to replay and changed loop to replay in the lua, but it said this for both attempts

12:13:01.474 Players.Ayd3nL.Backpack.Flamethrower.Main:7: attempt to index nil with ‘Replay’ - Server - Main:7
12:13:01.474 Stack Begin - Studio
12:13:01.474 Script ‘Players.Ayd3nL.Backpack.Flamethrower.Main’, Line 7 - function OnActivated - Studio - Main:7
12:13:01.474 Stack End - Studio
12:13:01.641 Players.Ayd3nL.Backpack.Flamethrower.Main:20: attempt to index nil with ‘Replay’ - Server - Main:20
12:13:01.641 Stack Begin - Studio
12:13:01.641 Script ‘Players.Ayd3nL.Backpack.Flamethrower.Main’, Line 20 - function OnDeactivated - Studio - Main:20
12:13:01.641 Stack End - Studio

Except replay would be loop in ur script.

Wait u edited, ill try that

This seems like the “Sound” is not even existing in the Handle… could you send a screenshot of the located sound please?

This worked after you edited it :slight_smile: thanks

1 Like

Oh, alright! Glad i could help.