Why dosent It play my animation?

I want to make it where it plays a animation on click and it is not playing it.
No errors are popping up in output.
Animation Is Still A Part Of Tool: image
Code:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Button1Down = mouse.Button1Down
local Players = game:GetService(“Players”)
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character

Button1Down:Connect(function(swing1)
local animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.animation)
end)

You didn’t play the animation

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Character = player.Character or player.CharacterAdded:Wait()

mouse.Button1Down:Connect(function()
    local animation = Character.Humanoid:LoadAnimation(script.Parent.animation)
    animation:Play()
end)

For future reference, indent your code and put them in code blocks ``` (these things).

Looking at your code, there’s several problems.
For one thing, you should use your Character variable when loading the animation and do it outside of the function.
Now your main problem is you’re not actually playing the animation and Button1Down should be Mouse.Button1Down

local Character = LocalPlayer.Character
local animation = Character.Humanoid:LoadAnimation(script.Parent.animation) 

Mouse.Button1Down:Connect(function(swing1)
      animation:Play()
end)

still does not play
bruh moment

you’re doing Button1Down, not Player:GetMouse().Button1Down. It should have errored, so check the console everytime you’re debugging

Can you check that the script.Parent.animation is a valid Animation object, and is owned by you?

yes i own it and it is valid eee

I would implement adding print statements then to check what runs and what doesn’t:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Character = player.Character or player.CharacterAdded:Wait()

mouse.Button1Down:Connect(function()
    print("Mouse fired")
    local animation = Character.Humanoid:LoadAnimation(script.Parent.animation)
    animation:Play()
    print("Animation playing")
end)

Also, make sure the animation body type is valid to what your rig body type is (R15 animation should be an R15 body)

still doesnt work bruhhhh thanks for helping me right now though

Did anything else Output then?

they all output
image

This sounds like it could be a problem with your animation priority.
Check that the animation you made has an animation priority of action.

Works but animation is slightly bugged

What do you exactly mean by bugged?

Fixed the animation thanks alot!

um i was reading the dev hub on the Humanoid:LoadCharacter() is deprecated. mentioned here so maybe try using another method of playing animation like animation controller maybe?

deprecated meaning it is strongly suggested to use the newer method, it doesn’t mean it wont work.

Instead of using Button1Down, you need to use Activated. So replace the lines with this:

script.Parent.Activated:Connect(function()
          local animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.animation)
          animation:Play()
end)

It might also work with Button1Down, probably the issue is because it’s a LocalScript. If it doesn’t work, try it on a Server-sided script


He’s not using LoadCharacter() but LoadAnimation().

Deprecated means the API is not supported anymore, and there’s a better alternative. Deprecateds are never supported.

oh yeah sorry I misspelled that, i meant to say “LoadAnimation” but nice catch.
LoadCharacter is function of the player not the character’s humanoid. eek