This is because you are referencing the animation as its name idleanim when its still named Animation1 in the script. So instead it would be this:
local Toll = script.Parent
local idleanim = Instance.new("Animation")
idleanim.AnimationId = "rbxassetid://7987783795"
local swinganim = Instance.new("Animation")
swinganim.AnimationId = "rbxassetid://7983245766"
local swinganim2 = Instance.new("Animation")
swinganim2.AnimationId = "rbxassetid://7987827486"
Toll.Equipped:Connect(function(Animation1)
local Animation1 = script.Parent.Parent.Humanoid:LoadAnimation(idleanim)
Animation1.Priority = Enum.AnimationPriority.Movement
Animation1:Play() while true do
wait(0.2)
print("Looping")
if Toll.Unequipped then
break
end
end
end)
Toll.Activated:Connect(function()
local swing1 = script.Parent.Parent.Humanoid:LoadAnimation(swinganim)
local swing2 = script.Parent.Parent.Humanoid:LoadAnimation(swinganim2)
swing1:play()
wait(0.5)
swing1:stop()
wait(0.01)
swing2:Play()
wait(0.5)
swing2:Stop()
end)
Toll.Unequipped:Connect(function()
Animation1:Stop()
end)
Also it is very inefficient to use a while true do loop for looping an animation when you can set an animation to looping in its properties or the animation itself.
Remove the local when defining Animation1 in the equip script to fix this, also why are you loop checking if the tool is unequipped in the equip function? That is completely pointless since you have a function when the tool unequips already.
--do note that tool animations dont replicate to the server
local player = game.Players.LocalPlayer
local idleAnimPlayer
local Anim = --reference the animation here, save it in replicated storage.
Tool.Equipped:Connect(function()
idleAnimPlayer = player.Character.Humanoid.Animator:LoadAnimation(Anim)
idleAnimPlayer:Play
idleAnimPlayer.Looped = true
end)
Tool.Unequipped:Connect(function()
idleAnimPlayer:Stop()
end)