Animations on click?

Hello, I’m an absolute noob when it comes to scripting, so I need help putting an attack animation on players.

After reading this: https://developer.roblox.com/en-us/articles/using-animations-in-games, I had no idea where to put the scripts anyway. I’m sorry if this is a simple question.

Basically, how am I supposed to make the animation run (on players), when they left click? Also, will this work with any button (A, right click, D, etc.)?

1 Like

could try this

lp = game.Players.LocalPlayer
mouse = lp:GetMouse()
mouse.Button1Down:Connect(function()
anim = Instance.new('Animation')
anim.AnimationId = "rbxassetid://id'
lp.Character.Humanoid:LoadAnimation(anim):Play()
end)
1 Like

Use UserInputService
Animations should always be client side
https://developer.roblox.com/en-us/api-reference/event/UserInputService/InputBegan

local UserInputService = game:GetService("UserInputService")
 local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")

UserInputService.InputBegan:Connect(function(Input, gameProcess)
if Input.KeyCode == Enum.KeyCode.D then
--this if you want it to be a key.
end
if Input.UserInputType == Enum.UserInputType.MouseButton1 then
-- this is if you want to be a mouse click
local Animation = -- Make an animation object put in the script  and place animation Id in object)
local AnimationLoad = humanoid:LoadAnimation(Animation)
AnimationLoad:Play() -- How to tell the script when to start the animation.
end
end)
1 Like

I’ll try those out, thank you!