I am not able to get this code to work, its suppose to change the idle animation and walking animation when equipping a tool and remove them when unequipping.
-- Assuming this script is a child of the Tool
local Tool = script.Parent
-- Declarations for necessary variables
local equippedIdle
local walkAnimation
local humanoid
local isEquipped = false
-- Function to load animations
local function loadAnimations(character)
humanoid = character:WaitForChild("Humanoid")
equippedIdle = humanoid:LoadAnimation(game.ReplicatedStorage.Fists.Animations.Idle)
walkAnimation = humanoid:LoadAnimation(game.ReplicatedStorage.Fists.Animations.Walk)
end
-- Function to handle movement
local function handleMovement(speed)
if isEquipped then
if speed > 0 then -- Walking
walkAnimation:Play()
equippedIdle:Stop()
else -- Idle
equippedIdle:Play()
walkAnimation:Stop()
end
end
end
-- Equipped event
Tool.Equipped:Connect(function()
local character = Tool.Parent
loadAnimations(character)
isEquipped = true
-- Play the equipped idle animation
equippedIdle:Play()
-- Connect to the Humanoid's running event
humanoid.Running:Connect(handleMovement)
end)
-- Unequipped event
Tool.Unequipped:Connect(function()
isEquipped = false
-- Stop the animations when the tool is unequipped
equippedIdle:Stop()
walkAnimation:Stop()
end)```
** You are now Level 2! **