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

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

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

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.

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