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

Why is my sword idle animation not working?

So I have a sword that has multiple attack animations and a Idle animation when you enable it, but for some reason the idle animation doesnt work (I remember a few months ago it did), heres the script:

local Tool = nil
local animScript = nil
script.Parent.Equipped:Connect(function()
	Tool = script.Parent
	animScript = Tool.Parent:WaitForChild("Animate")
	animScript:WaitForChild("toolnone"):WaitForChild("ToolNoneAnim")
	animScript.toolnone.ToolNoneAnim.AnimationId = "https://roblox.com/asset/?id=5341725784"
end)

script.Parent.Equipped:Connect(function()
	Tool = script.Parent
	animScript:WaitForChild("toolnone"):WaitForChild("ToolNoneAnim")
	animScript.toolnone.ToolNoneAnim.AnimationId = "https://roblox.com/asset/?id=5341725784"
end)

1 comment

0

Use the normal Roblox sword animations.

2 answers

You have to load in the animation inside the humanoid for it to work. Since this is probably a local script you first define the humanoid.

local Tool = nil
local animScript = nil

local humanoid = script.Parent.Parent:FindFirstChild("Humanoid") 
--The humanoid is defined like this because since the tool is equipped, it will on your char.

script.Parent.Equipped:Connect(function()
    Tool = script.Parent
    animScript = Tool.Parent:WaitForChild("Animate")
    animScript:WaitForChild("toolnone"):WaitForChild("ToolNoneAnim")
   local animation = humanoid:LoadAnimation( animScript.toolnone.ToolNoneAnim)
    animation:Play()
end)

Also, it seems like you may have duplicated your equipped event, since the animationID is the exact same.

4 comments

0

ok thank you.

0

I tried it, and got the error "Attempt to index nil with LoadAnimation"

0

Oh, I think I see the problem, try putting the humanoid variable inside the equipped event.

0

ok

OK i have been through this problem before, all u need to do is

local Tool = script.Parent

local player = game:GetService('Players').LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild('Humanoid')
Idle = Instance.new("Animation")
Idle.AnimationId = "http://www.roblox.com/asset/?id=5882776048"

Tool.Equipped:Connect(function()
	idleanim = player.Character.Humanoid:LoadAnimation(Idle)
	idleanim:Play()
end)

Tool.Unequipped:Connect(function()
	idleanim = player.Character.Humanoid:LoadAnimation(Idle)
	idleanim:Stop()
end)

2 comments

0

ok

0

I tried it, the animation plays but when I unequip the tool, the animation keeps playing

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