Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

[Animation] Not sure how to add sound to an animation | Any suggestions?

I've been stuck on this for awhile and can't seem to find anything on this matter. I've been trying to play a sound during an animation (at the start of the animation) and can't seem to get it right, need any help I can get.

Here's the script I have for this:

wait(.5)

Player = game.Players.LocalPlayer.Character
animation1 = Player.Humanoid:LoadAnimation(script.Animation1)
animation2 = Player.Humanoid:LoadAnimation(script.Animation2)
animation3 = Player.Humanoid:LoadAnimation(script.Animation3)
CanEmote = true

game:GetService('UserInputService').InputBegan:Connect(function(Input, GameProcessed)
	if not GameProcessed and Input.KeyCode == Enum.KeyCode.P then
		local emote = math.random(1,3)
		if emote == 1 and CanEmote == true then
			animation1:Play()
			CanEmote=false
			wait(2)
			CanEmote=true

		elseif emote == 2 and CanEmote == true then
			animation2:Play()
			CanEmote=false
			wait(2)
			CanEmote=true

		elseif emote == 3 and CanEmote == true then
			animation3:Play()
			CanEmote=false
			wait(2)
			CanEmote=true
		end
	end
end)

1 answer

✓ Accepted answer

You can just play your song together with animation:Play(), like this:

SomeSound:Play()
animation3:Play()
CanEmote=false
wait(2)
CanEmote=true

If you want to play the sound in a specific part of the animation, you can try adding a delay() thread or using Animation Events.

This discussion is preserved as it was. New answers, comments, and votes are closed.