-- Tools
local tool = script.Parent
local handle = tool:WaitForChild("Handle")
-- Player
local players = game:GetService("Players")
local player = players.LocalPlayer
local char = player.Character
if not char then
char = player.CharacterAdded:Wait()
end
local humanoid = character:FindFirstChild("Humanoid")
-- Animation
local animation = Instance.new("Animation")
animation.AnimationId = "https://www.roblox.com/library/5446663397/swordequip"
local animationtrack = humanoid:LoadAnimation(animation)
tool.Equipped:Connect(function()
print("tool equipped")
animationtrack:Play()
end)
My script is not working because local char = player.Character is throwing an error, that it can't index the character

4 comments
This will only work client-sided.
yes, his localscript is in a tool
the problem is always the character. It fails to index it or (nil).
Maybe replace game:GetService("Players") with game.Player