Why Won't My Animation Play?

Hey what’s up haven’t scripted in ages so I need help with making an animation play. What’s wrong here???

local Players = game:GetService("Players")
local player = script.Parent.Parent.Parent
task.wait()
local leaderstats = player:WaitForChild("leaderstats")
local Time = leaderstats:WaitForChild("Time")
local Damage = 0
local character = game.Workspace:FindFirstChild(player.Name)
local humanoid = character:FindFirstChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animation = script.Parent:WaitForChild("Animation")
local animTrack = animator:LoadAnimation(animation)

script.Parent.Activated:Connect(function()
	print("Tool activated")
	animTrack:Play()
end)

ignore the messy variables they are used later on. The tool activates but the animation never plays

2 Likes

Is the Animation owned by the place owner?
Does “Tool activated” print?

Yeah I own game and animation and tool activated prints

try this:


local player = script.Parent.Parent.Parent
local anim = --add your animation
local character = player.Character or player.CharacterAdded:Wait()
animtrack = character:FindFirstChildOfClass("Humanoid"):LoadAnimation(anim)
local Players = game:GetService("Players")
local player = script.Parent.Parent.Parent
task.wait()
local leaderstats = player:WaitForChild("leaderstats")
local Time = leaderstats:WaitForChild("Time")
local Damage = 0
local character = player.Character or player.CharacterAdded:Wait()
local animation = script.Parent:WaitForChild("Animation")
animTrack = character:FindFirstChildOfClass("Humanoid"):LoadAnimation(animation)
local debounce = false

script.Parent.Activated:Connect(function()
	print("Tool activated")
	animTrack:Play()
end)

still doesn’t work but it prints tool activated

Oh sorry, I didn’t realize this was a normal script. It only works in a local script

do animations only work in local scripts? Can i not play on server so everyone sees it?

Animations can be called in a local script or a server script, but the player character is typically a default instance of the server and not the client; if you wanted to have an animation that only the player could see you would have to do that a different way.

By default, playing your animation through a local script will still make it visible for others, because it is the server’s instance of the character that is being animated. His script that he provided gets access to the player’s character via the client when he establishes the character as player.Character, which is a property of the player (client) that associates the player with their respective in-game character.

2 Likes

So if I was holding a sword when the animation plays locally will that sword also move along with the animation? And then have hit boxes triggered?

For your purposes, the animation is not playing locally, you are playing it in the server. But, yes, for what you are doing the sword will move and since the hitbox is attached to the sword itself, once it comes into contact with another hitbox whatever interaction you’ve established at that point will occur.

1 Like
local Players = game:GetService("Players")
local player = script.Parent.Parent.Parent
wait()

local leaderstats = player:WaitForChild("leaderstats")
local Time = leaderstats:WaitForChild("Time")
local Damage = 0

local character = game.Workspace:FindFirstChild(player.Name)

if character then
    local humanoid = character:FindFirstChild("Humanoid")

    if humanoid then
        local animator = humanoid:WaitForChild("Animator")

        if animator then
            local animation = script.Parent:WaitForChild("Animation")
            local animTrack = animator:LoadAnimation(animation)

            script.Parent.Activated:Connect(function()
                print("Tool activated")
                animTrack:Play()
            end)
        else
            warn("Animator not found in humanoid.")
        end
    else
        warn("Humanoid not found in character.")
    end
else
    warn("Character not found in Workspace.")
end

It’s most likely the issue that the priority isn’t set, unless you set it in the Animation Editor. So the animation is probably playing. Insert this line after animTrack is defined.

animTrack.Priority = Enum.AnimationPriority.Action --mess around with this to see which priority fits best
1 Like

If you are using a server Script then all you should need to do to play an animation when the Tool is activated is this:

local tool = script.Parent

local animationTrack

tool.Equipped:Once(function()
	animationTrack = tool.Parent.Humanoid.Animator:LoadAnimation(script.Animation)

	print"AnimationTrack successfully loaded"
end)

tool.Activated:Connect(function()
	animationTrack:Play()

	print"Activated"
end)

If the animation does play when you activate the Tool but plays incorrectly, then you need to adjust the AnimationTrack’s priority like @Laser_Gun5540 suggested by doing this:

local tool = script.Parent

local animationTrack

tool.Equipped:Once(function()
	animationTrack = tool.Parent.Humanoid.Animator:LoadAnimation(script.Animation)
	animationTrack.Priority = Enum.AnimationPriority.Action4 -- I set it to the highest priority for debugging purposes

	print"AnimationTrack successfully loaded"
end)

tool.Activated:Connect(function()
	animationTrack:Play()

	print"Activated"
end)

If you try both options but the animation still refuses to play, then the only possible problem I could think of is that there’s something wrong with how the Animation itself was made. You could also check to see if you remembered to publish the Animation before using it because you do need to publish it before you can use it

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.