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

How would i play an animation through a script?

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

✓ Accepted answer
-- 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

2 comments

0

Thanks.

0

Upvote? Thx ;)

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