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

Why is my sword idle animation not working?

Asked by 3 years ago

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)
0
Use the normal Roblox sword animations. Rochie_Builds 0 — 3y

2 answers

Log in to vote
0
Answered by
QWJKZXF 88
3 years ago

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.

0
ok thank you. Sabertooth11123 38 — 3y
0
I tried it, and got the error "Attempt to index nil with LoadAnimation" Sabertooth11123 38 — 3y
0
Oh, I think I see the problem, try putting the humanoid variable inside the equipped event. QWJKZXF 88 — 3y
0
ok Sabertooth11123 38 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

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)

0
ok Sabertooth11123 38 — 3y
0
I tried it, the animation plays but when I unequip the tool, the animation keeps playing Sabertooth11123 38 — 3y

Answer this question