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

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

Asked by 3 years ago

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

Log in to vote
0
Answered by
Necro_las 412 Moderation Voter
3 years ago

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.

Ad

Answer this question