How do I have audio play with a while loop?

Hey all, I want to play an audio loop simultaneously with a while loop but however, it restarts every time the while loop starts again and that’s not what I am trying to achieve, what I want is it plays while the loop is going on, not every time the loop restarts.

if humanoid and victimhead then --if script found humanoid and head, searches for something only players have
while (victimhead.Position - head.Position).magnitude < 5 and humanoid.Health > 0 do
				scaredsound:Play()
						if anger < 100 then
							anger = anger + 1
							print(anger)
							wait(1)
					end
				end
				scaredsound:Stop()
				end

ok bruh nevermind i never thought to use sound.Playing = true, idk how i didn’t think of it. ig this serves as a lesson to use your brain more

1 Like

The reason could be because the humanoid dies, which stops the while loop, and then restarts it when the humanoid respawned.

2 Likes

Make a CanPlay value, and enable that value in the loop, detect if the value is enabled and play the sound.

1 Like