How to make an audio play again only after the audio finishes playing

Hello everybody, as you can see the from the title, I’m trying to make an audio play again only after the audio finishes playing. Incase if you didn’t understand what I was trying to say, let me explain with more details. So I’m making a move where a player holds “R”, the player will perform a barrage, I’m trying to make a sound play for every second the player holds “R”. But the problem is, when the audio plays, the audio plays again before the played audio ends. How should I modify the script so that the audio only plays again after the played audio ends. You can see the script below, (Swift1 is the audio that I’m having a problem with). I apologise for my bad english.

-- Godly Strike
local BarrageNumber = 1
local barragecount = 0
function GodlyStrike()
	--// Cooldown and Performing Check\\--
	if GodlyStrikeCD.Value == true or PerformingAction.Value == true or Stunned.Value == true then return end
	--// Applying the Changes\\--
	PerformingAction.Value = true
	GodlyStrikeCD.Value = true
	local holding2 = true
	mouse.KeyUp:Connect(function(Key)
		if Key == "r" then
			holding2 = false
		end
	end)
	human.WalkSpeed = 14
	human.JumpPower = 0
	LoopedBarrage:Play()
	rushsound:Play()
	repeat
		coroutine.resume(coroutine.create(function()
			Swiftsfx1:Play()
			Swiftsfx1.Ended:Wait()
		end))
		barragecount = barragecount + 1
		damage(rightarm, rightarm.CFrame * CFrame.new(0, -1, 0) * CFrame.new(math.random(-0.25, 0.25), math.random(-0.25, 0.25), math.random(-0.25, 0.25)) ,5, 0.5, 0, 0.25, hrp.CFrame.lookVector * 0, "rbxassetid://580201163", 0.075, Color3.new(1, 1, 1), 6708523560, 1)
		damage(leftarm, leftarm.CFrame * CFrame.new(0, -1, 0) * CFrame.new(math.random(-0.25, 0.25), math.random(-0.25, 0.25), math.random(-0.25, 0.25)) ,5, 0.5, 0, 0.25, hrp.CFrame.lookVector * 0, "rbxassetid://580201163", 0.075, Color3.new(1, 1, 1), 6708523560, 1)
		--damage(torsohitbox, torsohitbox.CFrame * CFrame.new(0, -1, 0) * CFrame.new(math.random(-0.25, 0.25), math.random(-0.25, 0.25), math.random(-0.25, 0.25)) ,5, 0.5, 0, 0.25, hrp.CFrame.lookVector * 0, "rbxassetid://580201163", 0.075, Color3.new(1, 1, 1), 6708523560, 1)
		damage(rightleg, rightleg.CFrame * CFrame.new(0, -1, 0) * CFrame.new(math.random(-0.25, 0.25), math.random(-0.25, 0.25), math.random(-0.25, 0.25)) ,5, 0.5, 0, 0.25, hrp.CFrame.lookVector * 0, "rbxassetid://580201163", 0.075, Color3.new(1, 1, 1), 6708523560, 1)
		damage(leftleg, leftleg.CFrame * CFrame.new(0, -1, 0) * CFrame.new(math.random(-0.25, 0.25), math.random(-0.25, 0.25), math.random(-0.25, 0.25)) ,5, 0.5, 0, 0.25, hrp.CFrame.lookVector * 0, "rbxassetid://580201163", 0.075, Color3.new(1, 1, 1), 6708523560, 1)
		wait(0.1)
	until holding2 == false or Stunned.Value == true or barragecount >= 60
	LoopedBarrage:Stop()
	rushsound:Stop()
	barragecount = 0
	human.WalkSpeed = oldws
	human.JumpPower = oldjp
	--// Cooldown\\--
	PerformingAction.Value = false
	coroutine.resume(coroutine.create(function()
		wait(15)
		GodlyStrikeCD.Value = false
	end))
end

Any kind of help would be appreciated.

Try

delay(Swiftsfx1.TimeLength, function()
Swiftsfx1:Play()
end)

It’s not really working.
https://gyazo.com/da533cf0b92a9949926bc03fdb6a5153

This is how the sound, sounds like.
https://gyazo.com/ff3919147dbb7bd21c20491ba95fb5d0

There is a loop checkbox in the properties panel of the audio which you can enable if adding it through instance. Or you can use:

Sound.Ended:Connect(function()
    PlayFunction() -- Call the function again
end)

Add this inside the function that you are calling inside it

full example:

function Calling()
    sound = script.Parent.Sound
    sound:Play()
    sound.Ended:Connect(function()
        Calling()
    end)
end

script.Parent.MouseButton1Down:Connect(function()
    Calling()
end)
1 Like

Sadly this doesn’t work either. Scripting can really be frustrating sometimes. After using the move, my ping rose to 5000 and my Studio crashed.

What’s the error msg in the output panel?

I wasn’t able to see the Output since my Studio crashed right after using the move, but I don’t think any error msg showed up.

Wait how long is the audio? Maybe it needs the longer script if to low.

Uh it’s extremely short, 0.496 seconds long.

Yea studio crashing because the loop going too fast. I have to go eat dinner when I"m back I’ll give you the script to make it work. Very sorry

Take you’re time, I don’t want anyone to apologise because of a script.

K back

Have you enabled Looped?

The audio? Yes I did looped it.

But the problem’s still not fixed though

Ok then you can use 1 of 2 scripts

You can use Debounces and when the player started holding R it will play the audio with looped on and make debounce to true

and the debounce will turn to false when the player stopped holding R

Also, Let me just get the main idea, Your problem is because they hold R and if they stop it continues to play?

That’s not the problem, it’s kind of hard to explain it with words so I’ll explain it with a gif.
https://gyazo.com/da533cf0b92a9949926bc03fdb6a5153

You can hear two noises, the first noise is basically a scream, and the second noise is suppose to play when the player is holding “R”. Just like this:
https://gyazo.com/d2e4ff5582f08bb086051f929a6c316a

But the noise cuts and plays again before the played sound actually ends.
I think the reason for this problem is because of the “Repeat” thing.
But I don’t really know how to fix this issue.

Oooh wait let me see something in your script brb

k send me the id of the sound please