I am trying to make the sound play once when the Tween starts to move, but instead if you keep clicking the sound will continue to play. Is there any way to debounce this?
ClickDetect.MouseClick:Connect(function()
local OpenSound = Instance.new("Sound")
OpenSound.Name = "OpeningSound"
OpenSound.Parent = script.Parent.Handle
OpenSound.Volume = 0.5
OpenSound.SoundId = "rbxassetid://" .. "7309104360"
wait()
if wait() then
if ReverseBool == false then
CoverTween:Play()
HandleTweenmove:Play()
OpenSound:Play()
CoverTween.Completed:Wait()
HandleTweenmove.Completed:Wait()
script.Parent.Handle.OpeningSound:Destroy()
ReverseBool = true
else
CoverTweenReverse:Play()
HandleTweenReverse2:Play()
OpenSound:Play()
CoverTweenReverse.Completed:Wait()
HandleTweenReverse2.Completed:Wait()
script.Parent.Handle.OpeningSound:Destroy()
ReverseBool = false
end
end
end)
if not(tween.PlaybackState == Enum.PlaybackState.Playing) then
...
to the beginning of the function. This will check if the tween (it’s enough if you check only one, maybe the longest one) is NOT playing, and you could only run the rest of the script if the tween is not playing, so they won’t overlap.
You can do the same thing and check if the audio is playing, and only play it if it’s not, but only do that if the audio is longer than the tween
That wouldn’t solve anything, as the function can still play multiple times, so the wait would do nothing. The best solution is to simply check if you can play it before playing it. Also, writing 2 functions for the same event is not a good idea, they might bug