So I am trying to figure out how to put animations in tools and it makes absolutely no sense. I've been able to have the animation work and everything but when the player dies and respawns it gives an error saying the animation isn't found in the script, and when I go into the tool after the error is shown the animation is clearly there. Here is the code in a local script in the tool:
local SWING_TIME = 2
local Players = game:GetService("Players")
local canSwing = true
local tool = script.Parent
local player = Players.LocalPlayer
local character = player.Character
if not character then
character = player.CharacterAdded:Wait()
end
local humanoid = character:WaitForChild("Humanoid")
local r6swing = script:WaitForChild("R6AnimationSwing")
local r15swing = script:WaitForChild("R15AnimationSwing")
while not character:IsDescendantOf(game.Workspace) do
wait()
end
local rigType = humanoid.RigType
local swing = nil
if rigType == Enum.HumanoidRigType.R15 then
swing = humanoid:LoadAnimation(r15swing)
elseif rigType == Enum.HumanoidRigType.R6 then
swing = humanoid:LoadAnimation(r6swing)
end
while swing.Length == 0 do
wait()
end
local swingSpeed = swing.Length / SWING_TIME
local function swingTool()
if canSwing == true then
-- Keep user from clicking until animation finishes
canSwing = false
swing:Play()
swing:AdjustSpeed(swingSpeed)
wait(SWING_TIME)
canSwing = true
end
end
tool.Activated:Connect(swingTool)

1 comment
Do you have a model so I can try it out in studio?