#Animation freezing and wont unfreeze upon dropping tool

1 messages · Page 1 of 1 (latest)

tepid bloom
#

Trying to use a custom tool hold animation, it freezes at a certain animationevent as intended but if i drop the item or delete it, the equip animation is completely stuck. I'm totally new to animations and scripting them if you cant already tell so please help + give feedback 🙏

#

🙏

agile masonBOT
#

studio** You are now Level 7! **studio

signal swallow
#

hmm

#

well first thing there is a memory leak, you wouldnt want to load a new animation on every equip & unequip

#

i suggest you load it outside kf these events and then play/stop as needed

signal swallow
#

instead of defining the track when the tool is equipped or unequipped, i suggest you define it directly after it's declared

#

can you copy the code and send it in a codeblock here

signal swallow
sacred slate
#

Make sure you turn off looped after animation is finished

#

That might fix

signal swallow
tepid bloom
#

wait wt

tepid bloom
signal swallow
#

copy your code

#

& paste it here but with lua at the top and at the bottom

#

not that

#

`

#

`

#

`

#

at top

#

and `

#

`

#

`

#

at bottom

#

no spaces or anything

tepid bloom
#

`local player = game.Players.LocalPlayer
local holdAnim = script.HoldAnim
local unequip = script["Unequip Anim"]
local track
local track2
local bool = false

script.Parent.Equipped:Connect(function()
bool = not bool
if bool == true then
track = player.Character.Humanoid:LoadAnimation(holdAnim)
track:Play()
track:GetMarkerReachedSignal("End"):Connect(function()
track:AdjustSpeed(0)
end)
end
end)

script.Parent.Unequipped:Connect(function()
track:Stop()
track2 = player.Character.Humanoid:LoadAnimation(unequip)
track2:Play()
end)

script.Parent.ChildRemoved:Connect(function()
track2:Play()
track:Stop()
end)`

signal swallow
#

like this i meant

tepid bloom
#

oh

#
local holdAnim = script.HoldAnim
local unequip = script["Unequip Anim"]
local track
local track2
local bool = false

script.Parent.Equipped:Connect(function()
    bool = not bool
    if bool == true then
        track = player.Character.Humanoid:LoadAnimation(holdAnim)
        track:Play()
        track:GetMarkerReachedSignal("End"):Connect(function()
            track:AdjustSpeed(0)
        end)
    end
end)

script.Parent.Unequipped:Connect(function()
    track:Stop()
    track2 = player.Character.Humanoid:LoadAnimation(unequip)
    track2:Play()
end)

script.Parent.ChildRemoved:Connect(function()
    track2:Play()
    track:Stop()
end)```
#

how does it help btw?

signal swallow
#

readability

tepid bloom
#

fair

signal swallow
#

are your animations looped?

tepid bloom
#

like if i do track:play it doesnt loop

signal swallow
#

ok

#

one sec

#

wait

#

wrong one

#
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")

-- Animations
local HoldAnimation = script.HoldAnim
local AnimationTrack1 = Animator:LoadAnimation(script.HoldAnim)
local UnequipAnimation = Animator:LoadAnimation(script["Unequip Anim"])
local Boolean = false

Player.CharacterAdded:Connect(function(NewCharacter)
    Character = NewCharacter
    Humanoid = NewCharacter:WaitForChild("Humanoid")
    Animator = Humanoid:WaitForChild("Animator")
end)

script.Parent.Equipped:Connect(function()
    Boolean = not Boolean

    if Boolean then
        AnimationTrack1:Play()
        AnimationTrack1:GetMarkerReachedSignal("End"):Connect(function()
            AnimationTrack1:Stop()
        end)
    end
end)

script.Parent.Unequipped:Connect(function()
    AnimationTrack1:Stop()
    UnequipAnimation:Play()
end)

script.Parent.ChildRemoved:Connect(function()
    UnequipAnimation:Play()
    AnimationTrack1:Stop()
end)
#

@tepid bloom

tepid bloom
#

when i equip, the animation plays and then resets like

signal swallow
#

ohh

#
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")

-- Animations
local HoldAnimation = script.HoldAnim
local AnimationTrack1 = Animator:LoadAnimation(script.HoldAnim)
local UnequipAnimation = Animator:LoadAnimation(script["Unequip Anim"])
local Boolean = false

Player.CharacterAdded:Connect(function(NewCharacter)
    Character = NewCharacter
    Humanoid = NewCharacter:WaitForChild("Humanoid")
    Animator = Humanoid:WaitForChild("Animator")
end)

script.Parent.Equipped:Connect(function()
    Boolean = not Boolean

    if Boolean then
        AnimationTrack1:Play()
        AnimationTrack1:GetMarkerReachedSignal("End"):Connect(function()
            AnimationTrack1:AdjustSpeed(0)
        end)
    end
end)

script.Parent.Unequipped:Connect(function()
    AnimationTrack1:Stop()
    UnequipAnimation:Play()
end)

script.Parent.ChildRemoved:Connect(function()
    UnequipAnimation:Play()
    AnimationTrack1:Stop()
end)
tepid bloom
signal swallow
#

oh wait

tepid bloom
#

is it joeover

#

wait

#

what if instead of stop or adjust speed

#

u use pause

#

would that work

signal swallow
#
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")

-- Animations
local HoldAnimation = script.HoldAnim
local AnimationTrack1 = Animator:LoadAnimation(script.HoldAnim)
local UnequipAnimation = Animator:LoadAnimation(script["Unequip Anim"])
local Boolean = false

Player.CharacterAdded:Connect(function(NewCharacter)
    Character = NewCharacter
    Humanoid = NewCharacter:WaitForChild("Humanoid")
    Animator = Humanoid:WaitForChild("Animator")
end)

script.Parent.Equipped:Connect(function()
    Boolean = not Boolean

    if Boolean then
        AnimationTrack:AdjustSpeed(1)
        AnimationTrack1:Play()
        AnimationTrack1:GetMarkerReachedSignal("End"):Connect(function()
            AnimationTrack1:AdjustSpeed(0)
        end)
    end
end)

script.Parent.Unequipped:Connect(function()
    AnimationTrack1:Stop()
    UnequipAnimation:Play()
end)

script.Parent.ChildRemoved:Connect(function()
    UnequipAnimation:Play()
    AnimationTrack1:Stop()
end)
#

try this

signal swallow
tepid bloom
# signal swallow same thing

19:57:01.432 Workspace.CYBORG1230987654.Torch.equip:22: attempt to index nil with 'AdjustSpeed' - Client - equip:22

#

doesnt play anims

signal swallow
#

wrong variable reference

#
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")

-- Animations
local HoldAnimation = script.HoldAnim
local AnimationTrack1 = Animator:LoadAnimation(script.HoldAnim)
local UnequipAnimation = Animator:LoadAnimation(script["Unequip Anim"])
local Boolean = false

Player.CharacterAdded:Connect(function(NewCharacter)
    Character = NewCharacter
    Humanoid = NewCharacter:WaitForChild("Humanoid")
    Animator = Humanoid:WaitForChild("Animator")
end)

script.Parent.Equipped:Connect(function()
    Boolean = not Boolean

    if Boolean then
        AnimationTrack1:AdjustSpeed(1)
        AnimationTrack1:Play()
        AnimationTrack1:GetMarkerReachedSignal("End"):Connect(function()
            AnimationTrack1:AdjustSpeed(0)
        end)
    end
end)

script.Parent.Unequipped:Connect(function()
    AnimationTrack1:Stop()
    UnequipAnimation:Play()
end)

script.Parent.ChildRemoved:Connect(function()
    UnequipAnimation:Play()
    AnimationTrack1:Stop()
end)
tepid bloom
#

moment of truth

#

ok @signal swallow now it has the same problem that i started with 😭

signal swallow
#

show a video

signal swallow
#

ok wait

tepid bloom
#

2 bugs

signal swallow
#

so the issue is, it doesnt play on the second time you equip it?

tepid bloom
#

if u equip, unequip, re-equip then anim doesnt play 😭

#

also if u drop the object like at the end

#

it sticks u in that anim

signal swallow
#

ok wait

#

script parent child removed is supposed to stop the animations when the tool gets removed?

signal swallow
#

one min

tepid bloom
signal swallow
#
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")
local Tool = script.Parent

-- Animations
local HoldAnimation = script.HoldAnim
local AnimationTrack1: AnimationTrack = Animator:LoadAnimation(script.HoldAnim)
local UnequipAnimation = Animator:LoadAnimation(script["Unequip Anim"])
local Boolean = false

Player.CharacterAdded:Connect(function(NewCharacter)
    Character = NewCharacter
    Humanoid = NewCharacter:WaitForChild("Humanoid")
    Animator = Humanoid:WaitForChild("Animator")
end)

Tool.Equipped:Connect(function()
    Boolean = not Boolean

    if Boolean then
        AnimationTrack1:Play()
        AnimationTrack1:GetMarkerReachedSignal("End"):Once(function()
            AnimationTrack1:Stop()
        end)
    end
end)

Tool.Unequipped:Connect(function()
    AnimationTrack1:Stop()
    UnequipAnimation:Play()
end)

Tool.AncestryChanged:Connect(function(_, Parent)
    if Parent ~= Player.Backpack and Parent ~= Character then
        -- Tool dropped
        AnimationTrack1:Stop()
        UnequipAnimation:Play()
    end
end)
tepid bloom
#

20:08:22.476 HoldAnim is not a valid member of LocalScript "Workspace.CYBORG1230987654.Torch.Torch Activate" - Client - Torch Activate:8

signal swallow
#
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")
local Tool = script.Parent

-- Animations
local HoldAnimation = script.HoldAnim
local AnimationTrack1: AnimationTrack = Animator:LoadAnimation(script.Parent.equip.HoldAnim)
local UnequipAnimation = Animator:LoadAnimation(script.Parent.equip["Unequip Anim"])
local Boolean = false

Player.CharacterAdded:Connect(function(NewCharacter)
    Character = NewCharacter
    Humanoid = NewCharacter:WaitForChild("Humanoid")
    Animator = Humanoid:WaitForChild("Animator")
end)

Tool.Equipped:Connect(function()
    Boolean = not Boolean

    if Boolean then
        AnimationTrack1:Play()
        AnimationTrack1:GetMarkerReachedSignal("End"):Once(function()
            AnimationTrack1:Stop()
        end)
    end
end)

Tool.Unequipped:Connect(function()
    AnimationTrack1:Stop()
    UnequipAnimation:Play()
end)

Tool.AncestryChanged:Connect(function(_, Parent)
    if Parent ~= Player.Backpack and Parent ~= Character then
        -- Tool dropped
        AnimationTrack1:Stop()
        UnequipAnimation:Play()
    end
end)
tepid bloom
#

20:13:06.865 HoldAnim is not a valid member of LocalScript "Workspace.CYBORG1230987654.Torch.Torch Activate" - Client - Torch Activate:8

#

😭

tepid bloom
#

yeah same error

signal swallow
#
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")
local Tool = script.Parent

-- Animations
local HoldAnimation = script.Parent.equip.HoldAnim
local AnimationTrack1: AnimationTrack = Animator:LoadAnimation(script.Parent.equip.HoldAnim)
local UnequipAnimation = Animator:LoadAnimation(script.Parent.equip["Unequip Anim"])
local Boolean = false

Player.CharacterAdded:Connect(function(NewCharacter)
    Character = NewCharacter
    Humanoid = NewCharacter:WaitForChild("Humanoid")
    Animator = Humanoid:WaitForChild("Animator")
end)

Tool.Equipped:Connect(function()
    Boolean = not Boolean

    if Boolean then
        AnimationTrack1:Play()
        AnimationTrack1:GetMarkerReachedSignal("End"):Once(function()
            AnimationTrack1:Stop()
        end)
    end
end)

Tool.Unequipped:Connect(function()
    AnimationTrack1:Stop()
    UnequipAnimation:Play()
end)

Tool.AncestryChanged:Connect(function(_, Parent)
    if Parent ~= Player.Backpack and Parent ~= Character then
        -- Tool dropped
        AnimationTrack1:Stop()
        UnequipAnimation:Play()
    end
end)
tepid bloom
#

same

#

error

#

😭

#

local HoldAnimation = script.Parent.equip.HoldAnim

#

this is line 8

#

idfk whats going wrong

signal swallow
#

are you sure your pasting the new script in

tepid bloom
#
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")
local Tool = script.Parent

-- Animations
local HoldAnimation = script.Parent.equip.HoldAnim
local AnimationTrack1: AnimationTrack = Animator:LoadAnimation(script.Parent.equip.HoldAnim)
local UnequipAnimation = Animator:LoadAnimation(script.Parent.equip["Unequip Anim"])
local Boolean = false

Player.CharacterAdded:Connect(function(NewCharacter)
    Character = NewCharacter
    Humanoid = NewCharacter:WaitForChild("Humanoid")
    Animator = Humanoid:WaitForChild("Animator")
end)

Tool.Equipped:Connect(function()
    Boolean = not Boolean

    if Boolean then
        AnimationTrack1:Play()
        AnimationTrack1:GetMarkerReachedSignal("End"):Once(function()
            AnimationTrack1:Stop()
        end)
    end
end)

Tool.Unequipped:Connect(function()
    AnimationTrack1:Stop()
    UnequipAnimation:Play()
end)

Tool.AncestryChanged:Connect(function(_, Parent)
    if Parent ~= Player.Backpack and Parent ~= Character then
        -- Tool dropped
        AnimationTrack1:Stop()
        UnequipAnimation:Play()
    end
end)```
#

this is it

signal swallow
#

one min

tepid bloom
#

alr

signal swallow
#

mind if im back in like 20 min

tepid bloom
#

allg

tepid bloom
signal swallow
tepid bloom
#

ping me when ur back with a possible solution

signal swallow
#

ok

signal swallow
#

i might have to help tomorrow, my brain isnt braining

tepid bloom
marble lance
#

try equipping the tool for the third time

tepid bloom
#

?

#

yeah thatd work

#

but main issue is

marble lance
#

Boolean = not Boolean goes from false to true (equip), true to false (second equip) and false to true (third equip)

tepid bloom
#

when i drop it, im still stuck in the animation

tepid bloom
#

the drop bug 😭

marble lance
tepid bloom
#

yh

marble lance
#

when dropping is the tool destroyed or dropped on the floor in workspace?

#

as in backspace

tepid bloom
#

i mean its the same bug for both

#

but dropped

marble lance
#

ok test my theory

#

does ancestry changed print anything

#

wait is it a localscrip tor serverscript

#

localscript*

#

localscripts dont run in workspace

#

so that'd be your issue when dropping it

#

iirc

#

usually when it comes to handling tools, i tend to handle it using a script external from the tool itself, since when it's destroyed and/or moved to a place where the code wouldnt run that defeats the purpose of handling cleanup

marble lance
#

as i can attach the module to the tool and clean it up when required

#

💪

signal swallow
signal swallow
marble lance
#

afaik

marble lance
signal swallow
#

a script with runcontext client would be better for this then

marble lance
#

aye

#

learnt something new today, the actual use of runcontext lmao

#

never really needed to explore it so not actually found a use case for it cause of the way i manage my codebase

signal swallow
#

true

marble lance
#

and attach it to the tool itself

#

😋

signal swallow
#

idk what that is, but if its a library, i dont think we need to go that far

marble lance
#

yea no

#

lmao

signal swallow
#

?

#

what are the things you've listed

marble lance
#

They’re libraries

#

Pretty useful for code cleanup

#

I personally use Trove

marble lance
#

This is sorta off topic so mb

tepid bloom
#

ts pmo 😢

#

ggwp

#

i give up lol, lmk if yall find a solution but until then ill just use the default anim so i can continue scripting other stuff

signal swallow
#

ill work on it tmrw

tepid bloom