Animation doesnt play

I was trying to make a sword with an animation in a local script, but it doesnt play. There are no errrors.

local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local animation = script.Parent:WaitForChild("Animatio")
local animator = character:WaitForChild("Humanoid"):WaitForChild("Animator")
local punchAnimation = animator:LoadAnimation(animation)

local canSwing = true
local debounce = 1

script.Parent.Activated:Connect(function()
	if canSwing == true then
		canSwing = false
		punchAnimation:Play()
		wait(debounce)
		canSwing = true
	end
end)

What can I do to fix this?

3 Likes

Use a normal script instead. If that doesn’t work I’m not too sure.

1 Like

I wouldnt be able to get the LocalPlayer then like I do here in line 1
local player = game:GetService("Players").LocalPlayer

1 Like

Yes you could.
Script.parent.parent would get the player.

1 Like

You can, you’ll just have to find it using FindFirstChild() or script.Parent or it really depends where the script is located.

1 Like

Rename this to “Animation”

1 Like

I now get the error
LoadAnimation requires the Humanoid object (Nolas154.Humanoid) to be a descendant of the game object

1 Like

@geometricalC2123 @Azul_Cult It still wouldn’t make any difference regardless cause Animations should be replicated via client & server I believe (And even still the LocalPlayer should be able to view the Animation on their side regardless)

@Nolas154_YT I’d check to see if the AnimationPriority in your Animation is set to Action if your other default animations could be overlapping it, either that or you’ll have to change the punchAnimation inside your Activated Event

local Plr = game.Players.LocalPlayer
local Char = Plr.Character or Plr.CharacterAdded:Wait()
local Animation = script.Parent:WaitForChild("Animation")
local Animator = Char:WaitForChild("Humanoid"):WaitForChild("Animator")

local canSwing = true
local DB = 1

script.Parent.Activated:Connect(function()
    if canSwing then
        canSwing = false
        local PunchAnim = Animator:LoadAnimation(Animation)
        PunchAnim:Play()

        wait(DB)
        canSwing = true
    end
end)

Another possible instance is if you exactly “own” the animation or not, cause if you don’t then it’ll be unable to be played

I have set the AnimationPriority to Action, tried your script but still nothing happens without any errors. Maybe the animation doesnt work for some reason ?

Instead of doing

local punchAnimation = animator:LoadAnimation(animation)

do

local humanoid = character:WaitForChild("Humanoid")
local punchAnimation = humanoid:LoadAnimation(animation)
1 Like

There is still no diffference.

What Is the parent of the script?
have you actually checked if

script.Parent.Activated:Connect(function()

is working
put a print("Working") and see what the out put is, if it’s nothing then the function isn’t even working

It does work, maybe I did something wrong with the animation itself?
My avatar is R6 and the animation was created on a R6 template so it should work?
edit: Parent of the script is the Tool itself

Is this script in a tool? by any chance

Yeah it is, i forgot to say that

Put this in

script.Parent.Activated:Connect(function()
        print(character)
	if canSwing == true then
		canSwing = false
		punchAnimation:Play()
		wait(debounce)
		canSwing = true
	end
end)

and if it doesn’t print the characters name then you need to find a better way to get the players character

It does print my players name.

Okay, I’m just going to test it out myself and see whats the problem is, okay?

Sure, it just wont play the animation

local Plr = game.Players.LocalPlayer
local Char = Plr.Character or Plr.CharacterAdded:Wait()
local Animation = script.Parent:WaitForChild("Animation")
local Animator = Char:WaitForChild("Humanoid"):WaitForChild("Animator")

print("Just to make sure that everything works right")

local canSwing = true
local DB = 1

script.Parent.Activated:Connect(function()
    print("Event fired")

    if canSwing then
        print("Attempting to load animation hopefully")
        canSwing = false
        local PunchAnim = Animator:LoadAnimation(Animation)
        PunchAnim:Play()

        wait(DB)
        print("Animation finished")
        canSwing = true
    end
end)

Did you re-publish the Animation so that it is set to Action?