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

Tool walking anim won't stop playing?

I've been working on a tool with custom walk and idle anims. The problem is, the running anim won't stop playing while the tool is equipped! The anims are supposed to only play while the tool is equipped, which went fine. The only problem is this walking animation one. It won't stop playing while you have the tool equipped. Below is the code for the weapon.

canAttack = true
local p = game.Players.LocalPlayer
local c = p.Character or p.CharacterAdded:Wait()
local Humanoid = c:WaitForChild('Humanoid')
repeat wait() until Humanoid ~= nil

local attack = Humanoid:LoadAnimation(script.Attack)
local walking = Humanoid:LoadAnimation(script.Walking)
local idle = Humanoid:LoadAnimation(script.Idle)
local moving = script.Parent.Moving

script.Parent.Equipped:Connect(function()
	script.Parent.Handle.Unsheath:Play()

	moving.Value = false
	equipped = true

end)

Humanoid.Running:connect(function(value)
	if value <= 0 then
		moving.Value = false
	elseif value > 0 then
		moving.Value = true
	end
end)

moving.Changed:Connect(function()
	if moving.Value == true and equipped == true then
		walking.Looped = true
		idle.Looped = false
		idle:Stop()
		walking:Play()
	end
	if moving == false and equipped == true then
		walking.Looped = false
		walking:Stop()
		idle.Looped = true
		idle:Play()
	end
end)

script.Parent.Activated:Connect(function()
	local attack = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack)
	
	if canAttack == true then
		script.Parent.Handle.Swing:Play()
		attack:Play()
		canAttack = false
		wait(.4)
		attack:Stop()
		canAttack = true
		script.Parent.CanDamage.Value = true
	end
end)

script.Parent.Unequipped:Connect(function()
	equipped = false	
	
	idle.Looped = false
	idle:Stop()
	walking.Looped = false
	walking:Stop()
end)

1 answer

✓ Accepted answer

Assuming moving is a BoolVal, at line 35 you checked if moving is true, not its value. You're supposed to do moving.Value == true (you did the same mistake multiple times in the script as well)

And also what's with the equipped at line 16, it's never been initialized before as a local var and will die when the function ends.

1 comment

0

Crap. Thanks, man! Gonna try this out. I hate when I make this mistake of not saying .Value!

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