#changing walking animation on tool..

15 messages · Page 1 of 1 (latest)

candid lynx
#

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)```
obsidian spade
#

whats wrong with it

candid lynx
sour gorgeBOT
#

studio** You are now Level 2! **studio

lean garnet
#

Find where the error is like **print(“Working”)**and if it prints back that part is working and go until it stops printing and find the exact line of code/s

candid lynx
#

aight

#

one moment

lean garnet
#

Start with the end

#

Just to make sure

candid lynx
#

@shadow elm @obsidian spade

From what i see here, nothing is working, the only print that is working is the one at the start of the game : ```lua
-- Assuming this script is a child of the Tool
print("Script it activated")
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)
print("animation loader work")
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()
print("working equipped")
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()
print("working unequipped")
isEquipped = false
-- Stop the animations when the tool is unequipped
equippedIdle:Stop()
walkAnimation:Stop()
end)

lean garnet
#

Does handleMovement need to be added yet?

candid lynx
#

wdym

lean garnet
#

—function to handle movement, is “handleMovement” supposed to be local handleMovement at the top? Sorry I’m trying to learn code