This section of my code isn't functioning as expected; anytime I'm in range, [solved]

I tried using continue and break, but neither worked. I’m sure there’s a method to design a debounce system, but I can’t figure it out. the code im working on is a coded heart beat sound that plays when the player is in range and the volume changes depending on the players distance everything works well. here is the snippet

while task.wait(.1) do
if script.Enab.Value then
script.HrtBeat:Play() – this part
else
script.HrtBeat:Pause()
end
end

the heart beat sound doesn’t play as it should it gets harassed by the while loop i want it to just play the looped audio any help i don’t normally code with sounds so this is my weakness

If I’m understanding well, the solution would be to wait until the heartbeat sound ends

you mean have a function and use the looped property like this?

script.foo.looped:connect(function()
–code
end

honestly I’m unsure how to make it affective

while task.wait(.1) do
	if script.Enab.Value then
		script.HrtBeat:Play()
		script.HrtBeat.Ended:Wait() -- add a event wait for sound to stop
	else
		script.HrtBeat:Pause()
	end
end

Also use three backticks ``` to format your code. Like so

```
– paste your code here
while task.wait(.1) do
```

1 Like

thanks I’ve never actually heard of .Ended before i will try using it in my code (edit)
works well but when the user leaves the area the sound still plays unlike before i’ll figure it out though

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