Sound During Animation Help

I currently have a working script that allows an animation to be run once each click. During these clicks, I want a sound to play that only the player can hear (I assume local Sound). I am unsure as to where/how to incorporate the sound playing when the animation is running/on click.

local debounce = false
script.Parent.Equipped:Connect(function(Mouse)
	Mouse.Button1Down:Connect(function()
		if not debounce then
			debounce = true
			animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation)
			animation:Play()
			animation.Stopped:Wait()
			debounce = false
		end
    end)
end)

Would love any help. :slight_smile:

Just a shot in the dark, but give it a try right after:
animation:Play()

Just make a variable pointing towards the sound you want played or, create a new sound with specified SoundId then play it after the animation:Play().

If you don’t understand, I can provide a script.

1 Like

If you mean sounds playing when a animation reaches a certain keyframe,
markers are very useful for that.

You have to manually add these markers when you make the animation, but once that is done it is fairly easy to tie a sound effect to it.

Simply use this function, which will return a Roblox signal object, connect it using :Connect(function) and play your sound effect inside that function.

This event should literally fire every time said marker/point is reached, if you place the marker at the very beginning of your animation it should play the sound right when the animation starts, stuff like this is also very useful if you want things such as footstep sounds to be synchronized with your walking animation.

AnimationTrack:GetMarkerReachedSignal("PlaySound"):Connect(function()
	SoundEffect:Play()
end)

AnimationTrack:Play()

This plays the sound when the marker is reached.

5 Likes