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

How do I play my Roblox Sword Animation?

Hey I'm having a little bit of trouble playing my animation here is the code:

local SwordAnim = script.Parent:WaitForChild("SwordAnim")

script.Parent.Activated:Connect(function()
	SwordAnim:Play()
end)

I don't know if im forgetting something or what

1 answer

You need to load the animation before you can play it. You will need to add this

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

local SwordAnim = script.Parent:WaitForChild("SwordAnim")
local SwordTrack = Humanoid:LoadAnimation(SwordAnim)

script.Parent.Activated:Connect(function()
	SwordTrack:Play()
end)

3 comments

0

It errored line 2

0

What did the error say?

0

Also are you using a LocalScript or a server script? The error may be caused from not using a localscript

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