How to make a character animate when you click and have a tool activated?

In ServerStorage, I have a tool (its a sunscreen bottle) and i want to make the player animate when they click their mouse but only when the tool is activated. I made an animation but idk if i did it correctly.
This is what I have so far:

This is not how animations work, you will need to publish first this to Roblox:

image

Then create an Animation object and on Properties > AnimationId you should put the ID of the animation you published.

Then with a Script you will need to use .Activated event to detect if the tool is being equipped while the mouse got clicked:

local Animation = Tool.Animation
local LoadedAnimation = Humanoid:LoadAnimation(Animation)

Tool.Activated:Connect(function()
	LoadedAnimation:Play()
end)

You need to export the animation. Copy the id, insert an animation and paste the id into the animationId.

And then you can load the animation using Animator | Roblox Creator Documentation and play it using AnimationTrack | Roblox Creator Documentation

local Tool = script.Parent
local Animation = script:FindFirstChild("Animation")
local player = script:FindFirstAncestorWhichIsA("Player") or game.Players:GetPlayerFromCharacter(script.Parent.Parent)
local character = player.Character
local AnimationTrack = character.Humanoid:FindFirstChildOfClass("Animator"):LoadAnimation(Animation)

Tool.Activated:Connect(function()
	AnimationTrack:Play()
end)

oh oops sorry I’ve never done animations before I’ll try this when I can

I added a click part to the script but it doesn’t work even without it

local Tool = script.Parent
local Animation = script:FindFirstChild("Animation")
local player = script:FindFirstAncestorWhichIsA("Player") or game.Players:GetPlayerFromCharacter(script.Parent.Parent)
local character = player.Character
local AnimationTrack = character.Humanoid:FindFirstChildOfClass("Animator"):LoadAnimation(Animation)
local mouse = game.Players.LocalPlayer:GetMouse()

Tool.Activated:Connect(function()
	game.ReplicatedStorage.Applying:FireServer(mouse.Hit)
	AnimationTrack:Play()
end)

(when I tested the animation in the editor which was very hard to do btw it worked fine so i dont think its that)

If this is in a local script you can use Players | Roblox Creator Documentation, is there any error in the output? Also, what doesn’t work?

Try using this:

local Tool = script.Parent
local Animation = script:FindFirstChild("Animation")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local AnimationTrack = character:WaitForChild("Humanoid"):FindFirstChildOfClass("Animator"):LoadAnimation(Animation)
local mouse = player:GetMouse()

Tool.Activated:Connect(function()
	game.ReplicatedStorage.Applying:FireServer(mouse.Hit)
	AnimationTrack:Play()
end)

It doesn’t work and the problem is that It just doesn’t do the animation when clicked