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

I need help with my equipping animation. Help?

Asked by 6 years ago
Edited 6 years ago

So I tried to play an equipping animation on my sword when I equip it. I did this through a local script. However, when I equip the sword, only the default equip animation is played. Please help me.

Here is my script:

local sword = script.Parent local humanoid = sword:FindFirstChild("Humanoid")

sword.Equipped:connect(function() if humanoid then local anim = sword:FindFirstChild("EquipAnim") if anim then local loadedAnim = humanoid:LoadAnimation(anim) if loadedAnim then loadedAnim:Play() end end end end)

1
can't help don't see any code.. perhaps your code block is nil awesomeipod 607 — 6y
0
lol hellmatic 1523 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago
local sword = script.Parent
local humanoid = game:GetService("Players").LocalPlayer.Character:FindFirstChild("Humanoid")

sword.Equipped:Connect(function()
    if humanoid then
        local anim = sword:FindFirstChild("EquipAnim")
        if anim then
            local loadedAnim = humanoid:LoadAnimation(anim)
            if loadedAnim then
                loadedAnim:Play()
            end
        end
    end
end)

The problem was your local humanoid = sword:FindFirstChild("Humanoid") part, there is no humanoid in your sword tool, which is what you're searching for when you do "sword:FindFirstChild()"

Also if you aren't already, you should run this on a LocalScript, instead of a Server Script.

0
Thanks! SweetNoodleSoup 14 — 6y
Ad

Answer this question