Equip loop animation not ending after unequipped

There is an animation when its equipped but I want a looping animation to show that they are holding the tool. but whenever i unequip, the animation is still looping. (local script btw)

local parent = script.Parent
local Handle = parent:WaitForChild("Handle")
local Creator = parent:WaitForChild("Creator")

local Players = game:GetService("Players")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
-- Ensure that the character's humanoid contains an "Animator" object
local Humanoid = character:WaitForChild("Humanoid")

-- Create a new "Animation" instance and assign an animation asset ID


-- Values
isEquiped = false

EquipAnim = parent.Animationss.Equip
IdleAnim = parent.Animationss.Idle

parent.Equipped:Connect(function()
	local Equip = Humanoid:WaitForChild("Animator"):LoadAnimation(EquipAnim)
	Equip:Play()
	isEquiped = true
	if isEquiped == true then
		wait()
		print("Equipped")
		local Idle = Humanoid:WaitForChild("Animator"):LoadAnimation(IdleAnim)
		Idle:Play()
	end
end)

parent.Unequipped:Connect(function()
	isEquiped = false
	if isEquiped == false then
		local Idle = Humanoid:WaitForChild("Animator"):LoadAnimation(IdleAnim)
		Idle:Stop()
	end
end)

you are loading animation track again and again, not referencing the same looping animation also, its like you are creating a cup(unfilled) with every equip and unequip, you creat and are filling the cup with equip, and creating another unfilled cup with unequip which you are unfilling again, not the same cups, different.

you should load animation once before both actions and then just manipulate that track like:
idle_anime = loadanimation(track)

tool.equip:connect(
idle_anime:Play()
)

tool.unequip:conenct(
idle_anime:Stop()
(

1 Like
  1. The animation wont show to other players
  2. The isEquiped is not needed
  3. refer to what @meet_theHAXER said
local parent = script.Parent
local Handle = parent:WaitForChild("Handle")
local Creator = parent:WaitForChild("Creator")

local Players = game:GetService("Players")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
-- Ensure that the character's humanoid contains an "Animator" object
local Humanoid = character:WaitForChild("Humanoid")

-- Create a new "Animation" instance and assign an animation asset ID


-- Values
isEquiped = false

EquipAnim = parent.Animationss.Equip
IdleAnim = parent.Animationss.Idle
local Idle = Humanoid:WaitForChild("Animator"):LoadAnimation(IdleAnim)
local Equip = Humanoid:WaitForChild("Animator"):LoadAnimation(EquipAnim)
parent.Equipped:Connect(function()
	Equip:Play()
	isEquiped = true
	if isEquiped == true then
		wait()
		print("Equipped")
		Idle:Play()
	end
end)

parent.Unequipped:Connect(function()
	isEquiped = false
	if isEquiped == false then
		Idle:Stop()
                Equip:Stop()
	end
end)

The code above me is the same exact thing what the dude in the replys is saying

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.