im trying to stop the idle animation from playing but i keep getting this error message:
21:11:05.776 Players.TheBossOfBancon.Backpack.pitchfork.servertool:10: attempt to index nil with ‘Stop’ - Server - servertool:10
code block:
local tool = script.Parent
local idle = nil
tool.Equipped:Connect(function()
local idle = tool.Parent.Humanoid.Animator:LoadAnimation(script:WaitForChild("idle"))
idle:Play()
end)
tool.Unequipped:Connect(function()
idle:Stop()
idle:Destroy()
end)
local cooldown = 5
local lastActivation = 0
tool.Handle.Touched:Connect(function(part)
if part.Name == "Handle" then
local player = game.Players:GetPlayerFromCharacter(tool.Parent)
local currentTime = tick()
if currentTime - lastActivation >= cooldown then
local use = tool.Parent:FindFirstChild("Humanoid"):LoadAnimation(script.use)
use:Play()
script.useS:Play()
script.pick:Play()
player.leaderstats.Cash.Value += 5
game.ReplicatedStorage.remotes.cooldown:Fire()
lastActivation = currentTime
end
end
end)
Use this. It’s better because you don’t have to load the animation each time. It should also fix your error.
local animation = script:WaitForChild("idle")
local character = tool.Parent
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local idle = animator:LoadAnimation(animation)
tool.Equipped:Connect(function()
idle:Play()
end)
tool.Unequipped:Connect(function()
idle:Stop()
end)