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

How would i play an animation through a script?

Asked by
exarlus 72
6 years ago

Basically i rigged a model and animated into the animation editor but i have no idea how i would get the animation to play through a script. Im not requesting im just asking what would I use?

1 answer

Log in to vote
0
Answered by
tek_o 56
6 years ago
-- Import animation
local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/Asset?ID=144911345"

-- Local variables
local animTrack = nil
local canPlay = true

function playShockAnim(Source)
    if canPlay then
        local player = game.Players.LocalPlayer.Character
        canPlay = false
        animTrack = player.Humanoid:LoadAnimation(animation) -- Load animation into Humanoid
        animTrack.KeyframeReached:connect(function(keyframeName) -- Bind function to KeyframeReached event
            if keyframeName == "ElectrocuteEnd" then
                canPlay = true
            end
        end)    
        animTrack:Play() -- Start the animation
    end
end
0
Thanks. exarlus 72 — 6y
0
Upvote? Thx ;) tek_o 56 — 6y
Ad

Answer this question