-- 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
Instead of putting it in an if statement, try connecting both with and or.
Like this:
local players = game:GetService("Players") local player = players.LocalPlayer local char = player.Character or player.CharacterAdded:Wait() local humanoid = char:FindFirstChild("Humanoid")
You can use GetPlayerFromCharacter to get the character of the Local Player.
local plr = game.Players.LocalPlayer local Player = game.Workspace[plr.Name] local char = game.Players:GetPlayerFromCharacter(Player)
This works for me everytime. :)