Audio Not Playing Full Length Before Repeating

Hello!
I am currently working on a tower defense game. I am having issues with the audio however. For fast firing towers, whenever they attack, their audio gets cut off by the next attack. I want it to play the full length of the audio every time it shoots as appose to it just restarting when it attacks again.

As you can see, when the fireate is shorter than the sound, it doesnt play the full sound.

Currently, this is the code:

local TimeWait = tower.HumanoidRootPart.Attack.TimeLength
		
tower.HumanoidRootPart.Attack:Play()
tower.HumanoidRootPart.Attack.Ended:Wait(TimeWait)

(its in a bigger script but that’s all that is relevant)

I’ve tried multiple different methods but I cant seem to figure out how to make it play the full audio every attack.

Any help is apreciated!

There’s a few suggestions I can give, I’ll admit haven’t got too much experience in sound objects but atleast an idea.

You could have the sound in replicated storage and clone it.

The sound can have a script to play it and once ended it gets destroyed…

I can’t see your script or Workspace, but I’d assume your using a single sound object. You’ll likely need multiple sound objects for them to overlap is what I’m thinking

1 Like

Duplicate audio objects and play them. Have a function do it for you:

local function playAudio(AudioInstance : Sound)
	local duplicate = AudioInstance:Clone()
	duplicate.Looped = false -- It should not loop, otherwise it won't be removed.
	duplicate.Parent = AudioInstance.Parent
	duplicate.Ended:Once(function()
		duplicate:Destroy()
	end)
	duplicate:Play()
end

I recommend using this as a module function instead of copying this in every tower you have.

1 Like
tower.HumanoidRootPart.Attack:Connect(playAttackSound)

The problem with that is that every tower has a unique sound effect. Currently all the attack sounds are simply called “Attack” and its contained inside the tower. But perhaps cloning it is what I need to do.

Oh gotcha, @Y_VRN post above a script for your sounds, seems to be what your looking for in that case :+1:.

1 Like

Yeah this works! Thanks for the help!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.