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

I tried making a script without Humanoid:LoadAnimation, would this work?

Asked by 2 years ago

I was wondering If this script works

local Humanoid = script.Parent:WaitForChild("Humanoid")
local animation = Instance.new("Animation")
animation.Parent = script.Parent
local AnimationTrack = Humanoid.animation:Play()

Anyway, since Humanoid:LoadAnimation doesn't work due to (As I have heard) It would cause some random accident of the servers I guess and wondering If this works

(Also the animation track Is Inside of the script)

1 answer

Log in to vote
1
Answered by 2 years ago

Your code can't work because an AnimationTrack is what the method :LoadAnimation() return. So it's impossible to load an animation without using :LoadAnimation() method because this one return an AnimationTrack that allows us to play it.

The best way to load an animation is by using an Animator. This is an example of how you can code it.

local function GetAnimationTrack(player, animation)
    local Character = player.Character
    if Character and (Character:FindFirstChild("Humanoid")) then
        local Humanoid = Character.Humanoid

        -- If the we dont find Aimator we create it.
        local Animator = Humanoid:FindFirstChild("Animator") or Instance.new("Animator", Humanoid)

        -- Load animation on the Animator and return the AnimationTrack
        return Animator:LoadAnimation(animation)
    end
end

local PunchingTrack = GetAnimationTrack(Player, script.PunchingAnimation) -- Put your real arguments.
PunchingTrack:Play() -- Now is possible to Play the animation.

If I answered your question you can Accept Answer and if you have any questions put them in the comments.

Ad

Answer this question