Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Animation continues playing after unequipped, how to fix?

I cant just wrap my head around this one. I feel like its super easy but it just never works. The error report is "Humanoid is not a valid member of Backpack". Can anyone help me fix this, I've been trying for hours.

local CanAttack = true
local player = game.Players.LocalPlayer
local char = player.Character

script.Parent.Equipped:Connect(function()
     local idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle)
     local attack = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack)


idle:Play()
end)

script.Parent.Activated:Connect(function()
	print("Rope Activated")
	local idleAnimation = script.Idle
	local attackAnimation = script.Attack
	local idle = script.Parent.Parent.Humanoid:LoadAnimation(idleAnimation)
	local attack = script.Parent.Parent.Humanoid:LoadAnimation(attackAnimation)
	idle:Stop()
	attack:Play()
	print('Animation Playing')
	wait(5)
	idle:Play()
	print('Animation Stopped')
end)

function onUnEquipped()
	local idleAnimation = script.Idle
	local idle = script.Parent.Parent.Humanoid:LoadAnimation(idleAnimation)
	idle:Stop()
end
script.Parent.Unequipped:Connect(onUnEquipped)

1 answer

We can use GetPlayingAnimationTracks to stop an animation. Lets say there is a dummy in the workspace.

for i,v in pairs(workspace.Dummy.Humanoid:GetPlayingAnimationTracks()) do
if v.Name == "animationname" then
v:Stop()
end
end

1 comment

0

This is an action from a player holding a tool. Not a NPC in the workspace.

This discussion is preserved as it was. New answers, comments, and votes are closed.