I am trying to make a punch animation when you click the mouse button or touch the screen, it has no errors and does not play the animation

This is the script:

local UserInputService = game:GetService(“UserInputService”)
local animationId = 15377435145

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild(“Humanoid”)
local animationController = humanoid:WaitForChild(“Animator”) – Change “Animator” to the name of your AnimationController

    local function playAnimation()
        local animationTrack = humanoid:LoadAnimation(animationId)
        animationTrack:Play()
    end

    character:WaitForChild("Humanoid").Died:Connect(function()
      
    end)

    humanoid.Died:Connect(function()
        
    end)

    UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
        if gameProcessedEvent then
            return
        end

        if input.UserInputType == Enum.UserInputType.MouseButton1 then
            playAnimation()
        end
    end)
end)

end)

4 Likes

Is the animation id set correctly?

1 Like

yep, it is no idea why its not playing no errors or nothing

1 Like

Add some debug statements and show us the output.
For example:

local UserInputService = game:GetService("UserInputService")
local animationId = 15377435145

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        local humanoid = character:WaitForChild("Humanoid")
        local animationController = humanoid:WaitForChild("Animator")

        local function playAnimation()
            print("Playing animation...")
            local animationTrack = humanoid:LoadAnimation(animationId)
            animationTrack:Play()
        end

        character:WaitForChild("Humanoid").Died:Connect(function()
            print("Character died...")
        end)

        humanoid.Died:Connect(function()
            print("Humanoid died...")
        end)

        UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
            if gameProcessedEvent then
                return
            end

            if input.UserInputType == Enum.UserInputType.MouseButton1 then
                print("Mouse button clicked...")
                playAnimation()
            end
        end)
    end)
end)

3 Likes

Currently you are loading your animation every single time you click, which is not good. Load the animation once and play that animation when you click.

Could you also please show us a screenshot of your character descendants in the workspace?

2 Likes

make sure you are the owner of the animation. otherwise it wont work

if your game is owned by a group, the group must own that animation
if your game is owned by you, you must own that animation

(theres no permission granting like with audios)

3 Likes