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

Animation isn't playing from Tool?

Asked by 2 years ago

I made a simple sword and want to activate an animation from the tool. I can't seem to get it to play and can't figure why any help will be greatly appreciated!

Tool Setup in Studio

1) All parts are Welded together not anchored, and Collide is turned on only in Handle atm

2) I have animated and published the animation to roblox and attached id to animation named "SwordSlash"

local Tool = script.Parent

--Variables
local swordAnim

--Animations
local swordSlash = Tool.Handle.SwordSlash

Tool.Activated:Connect(function()

    local humanoid = Tool.Parent:FindFirstChildWhichIsA("Humanoid")
    if humanoid then
        local animator = humanoid:FindFirstChildOfClass("Animator")
            if animator then
            swordAnim = animator:LoadAnimation(swordSlash)
            print("Got Here")
            swordAnim:Play()
            wait(1)
            end
    end

end)

I have tried different varations with Stop() and debounce, but kept simplifying to try to get it working. Lastily I added the animator line since, I read that Humanoid:LoadAnimation was deprecated. I can get the sword out and the print "Got Here" to run ,but animation doesn't play. If anyone has any insight I would love some help on this Thanks! - Froxty

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

There is "animation" and there is "animator". I think you are using animator instead of animation look at the image link below

https://ibb.co/nRbL0yF

0
From what I read on Roblox API (https://developer.roblox.com/en-us/api-reference/class/Animator). From what I read the animator is created automatically when Humanoid:LoadAnimation or AnimationController:LoadAnimation is called. I added line 13-14 to find for the generated animator and use it to play animation track saved as swordanim. Froxtyy 4 — 2y
0
I previously didn't have those lines and had it down to just find humanoid and local animationTrack = Humanoid:LoadAnimation(Slash) and it wasn't working with that either so, I tried the lines above - I believe it's reference correctly tho. Froxtyy 4 — 2y
Ad

Answer this question