Playing animation on a local script

I’m trying to play an aiming animation on client side but I’m not sure how to do it, but I know it has something to do with :LoadAnimation, the script below is shortened btw.

local Tool = script.Parent
local AimDown = false
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = workspace:WaitForChild(Player.Name)
local Humanoid = Character:WaitForChild("Humanoid")
local Module = require(Tool:WaitForChild("Setting"))
local Animations = {}

if Module.AimAnimationsEnabled and Module.AimIdleAnimationID ~= nil then
	local AimIdleAnimTest = Instance.new("Animation")
	AimIdleAnimTest.Name = "AimIdleAnim"
	AimIdleAnimTest.AnimationId = "rbxassetid://"..Module.AimIdleAnimationID
	AimIdleAnimTest.Parent = Tool

	AimIdleAnim = Tool:WaitForChild("AimIdleAnim")
	AimIdleAnim = Humanoid:LoadAnimation(AimIdleAnim)
	table.insert(Animations, AimIdleAnim)
end
if Module.AimAnimationsEnabled and Module.AimFireAnimationID ~= nil then
	local AimFireAnimTest = Instance.new("Animation")
	AimFireAnimTest.Name = "AimFireAnim"
	AimFireAnimTest.AnimationId = "rbxassetid://"..Module.AimFireAnimationID
	AimFireAnimTest.Parent = Tool

	AimFireAnim = Tool:WaitForChild("AimFireAnim")
	AimFireAnim = Humanoid:LoadAnimation(AimFireAnim)
	table.insert(Animations, AimFireAnim)
end
1 Like

You should be loading it onto the animator that’s directly under the humanoid. To play it get the animation track from the load animation function and do Track:Play()

2 Likes

@sonic_848 is right, It’s better to load the animation onto the Animator under the humanoid because it gives more control over animation states and allows us to use the Track:Play() method for smoother transitions. It’s also the recommended way for more advanced systems.

2 Likes

Pretty sure it is loaded onto animator, but I think if an animation is loaded onto an animator, it plays server-sided, but I’m trying to make the animation play cilent-sided.

There’s no other way to do it unless maybe you manually create the animation via tweening the body parts to certain positions at different times