Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to get sound to play in sync with the animations?

Asked by 4 years ago

The sword plays a random animation every time you click, this works fine, but I'm trying to get sound to sync with the animations, because when I spam click the mouse, you can barely hear the sound cause its being played so many times.

I tried adding a cool down, but that doesnt help. I was thinking on a debounce but I'm not sure how I would go about this.

here is the code:

Sword.Activated:Connect(function()

        Sword.Handle.Slash:Play()

        end)

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago
local debounce = false 
Sword.Activated:Connect(function()
if debounce then return end -- so it doesn't run if cooldown
debounce = true -- set cooldown to true
Sword.Handle.Slash:Play()
wait(cooldown) 
debounce = false -- set cooldown to false
 end)

debounce and cooldown are the same thing. Also there is a sound property called "IsPlaying" so you can check if the sound is already playing.

0
Thank you! Telasim0 6 — 4y
Ad

Answer this question