Script that makes character animate when a tool is activated and the mouse is clicked not working

In ServerStorage, I have a tool (its a sunscreen bottle) and inside i have a script and an animation inside of it: Screen Shot 2021-08-13 at 5.09.32 PM
Script:

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 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 should work, have you set the priority of the animation to Action?

You can do

AnimationTrack.Priority = Enum.AnimationPriority.Action

or follow this guide.

Ok, there are a few errors.

  1. You can not get the mouse from a server script, this is a local only feature.
  2. You can not use :FireServer() on a server script.

You could use the ReClass plugin to turn the script into a local script

honestly, I don’t see the point in using the reclass plugin just to change a script to a local script when you only have to copy the scripts stuff and paste it.

Cuz its way simpler

Reclass:
Click convert
Select local script

Traditional:
Go inside of script
Ctrl c
Make a new local script
Go inside of local script
Ctrl v

Also in this case you have to parent the animation to the new local script

I made a few changes but it still won’t work: Screen Shot 2021-08-13 at 10.10.42 PM
Script:

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 or player.CharacterAdded:Wait()
local AnimationTrack = character:WaitForChild("Humanoid"):FindFirstChildOfClass("Animator"):LoadAnimation(Animation)
AnimationTrack.Priority = Enum.AnimationPriority.Action

script.Parent.Applying.OnServerEvent:Connect(function()
	AnimationTrack:Play()
end)

LocalScript:

local tool = script.Parent
local re = tool:WaitForChild("Applying")


local mouse = game.Players.LocalPlayer:GetMouse()


tool.Activated:Connect(function()

	re:FireServer(mouse.Hit)
end)

When you do

Try

script.Parent.Applying.OnServerEvent:Connect(function(mouseHit)

I had to keep the local player = script:FindFirstAncestorWhichIsA("Player") or game.Players:GetPlayerFromCharacter(script.Parent.Parent) because its used to get the animation track but I did this script.Parent.Applying.OnServerEvent:Connect(function(mouseHit) AnimationTrack:Play() but it still didn’t work
Also, I still have the local script firing the remote event when the mouse is clicked so should I still keep that