Unequipped event not working

I am trying to create a tool that plays a custom animation and changes the walkspeed to 4 and turns the player back to normal when they unequip the tool.

The equip function works perfectly however the players walk animation is still the same and the players walkspeed is still 4 when they unequip the tool.

I tried putting the humanoid variable on the first line but it didn’t work.

script.Parent.Equipped:Connect(function()
	local Humanoid = script.Parent.Parent:WaitForChild("Humanoid")
	Humanoid.WalkSpeed = 4
	local AnimateWalk = script.Parent.Parent:WaitForChild("Animate"):WaitForChild("walk"):WaitForChild("WalkAnim")
	AnimateWalk.AnimationId = "rbxassetid://6121017216"
end)
script.Parent.Unequipped:Connect(function()
	local Humanoid = script.Parent.Parent:WaitForChild("Humanoid")
	Humanoid.WalkSpeed = 16
	local AnimateWalk = script.Parent.Parent:WaitForChild("Animate"):WaitForChild("walk"):WaitForChild("WalkAnim")
	AnimateWalk.AnimationId = "rbxassetid://913402848"
end)

I think because the tool is unequipped and you have to use player.Character.Humanoid

Not sure

Okay so I think that is the problem but now I can’t find the character.

I tried making the players name a variable and then searching the workspace for the variable but it gives no errors but still doesn’t work.

script.Parent.Equipped:Connect(function()
	local Humanoid = script.Parent.Parent:WaitForChild("Humanoid")
	Humanoid.WalkSpeed = 4
	local AnimateWalk = script.Parent.Parent:WaitForChild("Animate"):WaitForChild("walk"):WaitForChild("WalkAnim")
	AnimateWalk.AnimationId = "rbxassetid://6121017216"
end)
script.Parent.Unequipped:Connect(function(plr)
	local Name = script.Parent.Parent.Parent.Name
	local character = workspace:FindFirstChild(Name)
	local Humanoid = character:WaitForChild("Humanoid")
	local AnimateWalk = character:WaitForChild("Animate"):WaitForChild("walk"):WaitForChild("WalkAnim")
	AnimateWalk.AnimationId = "rbxassetid://913402848"
end)

Because I think you cant use WaitForChild on the character this problem was for me too

Hm? But I used FindFirstChild to find the character not WaitForChild.

local Humanoid = character:WaitForChild("Humanoid")
local AnimateWalk = character:WaitForChild("Animate"):WaitForChild("walk"):WaitForChild("WalkAnim")

I tried using FindFirstChild and character.Humanoid but none of it works.

You should create a new variable that saves the last player’s name. Then you should find the character or player with that name.

That is what I did however it gives off no errors but still doesn’t work.

script.Parent.Unequipped:Connect(function(plr)
	local Name = script.Parent.Parent.Parent.Name
	local character = workspace:FindFirstChild(Name)
	local Humanoid = character:WaitForChild("Humanoid")
	local AnimateWalk = character:WaitForChild("Animate"):WaitForChild("walk"):WaitForChild("WalkAnim")
	AnimateWalk.AnimationId = "rbxassetid://913402848"
end)

It saves the players name inside game.Players btw.

why you dont try to give the tool to the player when the player is completly loaded and stop using waitforchild and findfirstchild

Well maybe the problem is, while a player playing an animation by animate script then it won’t change the current animation to the new one. Because it’s already playing. I mean you can’t see any change while walking. I am using modules or local scripts for tool scripts like this.

Also looks like you added an extra “.Parent” from your earlier code which, if you haven’t changed the
script structure since, would try to get the name of the workspace instead of the Character/Model.

Side note:

You may want to consider using this function. It displays your intentions a lot better and will clean your code up quite a bit.