Animation Won't Stop

I am attempting to stop the animation, I’ve tried all of the solutions I know which is just rearranging code. It does not give me any output.

--// Variables || Made By CarbonFiber, edited by zaslonn
local eventFolder = game.ReplicatedStorage

--// Services
local dss = game:GetService('DataStoreService')
local TextService = game:GetService("TextService")

--// Events
local tieEvent = eventFolder.TieEvent

--// Functions
function CheckForTool(player)
	local char = player.Character
	local result = false
	
	for _,v in pairs(char:GetChildren()) do
		if v and v:IsA('Tool') and v:FindFirstChild('Authenticate') then
			local auth = require(v:WaitForChild('Authenticate'))
			
			if auth and auth.Type == 'Ziptie' then
				result = true
			end
		end
	end;
	
	for _,v in pairs(player.Backpack:GetChildren()) do
		if v and v:IsA('Tool') and v:FindFirstChild('Authenticate') then
			local auth = require(v:WaitForChild('Authenticate'))
			
			if auth and auth.Type == 'Ziptie' then
				result = true
			end
		end
	end;
	
	return result
end;



--// Event Connections
tieEvent.OnServerEvent:connect(function(player,otherPlayer,mode,etc,config)
	local handcuffTool = game.ServerStorage.Handcuffed:Clone()	
	local animation = otherPlayer.Character.Humanoid.Animator:LoadAnimation(script.Animations.Handcuffed)
	if otherPlayer then
		if mode == 'Tie' then
			local plrChar = player.Character
			local otherChar = otherPlayer.Character
			local result = CheckForTool(player)
			
			if not result then
				player:Kick('Exploit Action was recorded and sent to ROBLOX Servers for moderation.')
			end;
			
			
			--animator = otherPlayer.Character:WaitForChild("Humanoid"):WaitForChild("Animator")
			otherPlayer.Character.Humanoid:UnequipTools()

			for _, child in pairs(otherPlayer.Backpack:GetChildren()) do
				if child:IsA("Tool") and child.Name == "Cuffed" then
					child:Remove()
				end
			end

			handcuffTool.Name = "Cuffed"
			handcuffTool.Parent = otherPlayer.Backpack
			otherPlayer.Character.Humanoid:EquipTool(handcuffTool)
			animation:Play()
			--loadedanimations[1]:Play()
		
		elseif mode == 'Untie' then

			animation:Stop()
			otherPlayer.Character.Humanoid:UnequipTools()
			wait(0.1)
			for _, child in pairs(otherPlayer.Backpack:GetChildren()) do
				if child:IsA("Tool") and child.Name == "Cuffed" then
					child:Remove()
				end
			end
		
		end;
	end;
end)
local animation = otherPlayer.Character.Humanoid.Animator:LoadAnimation(script.Animations.Handcuffed)

Every time the event is fired you make a new AnimationTrack and play that one, losing the old animation variable and not being able to stop it.
Instead you should load the animation once for the other player and then store it somewhere (probably in a table), then play and stop that loaded animation.

Example:

local loadedAnimations = {} -- store animations here

-- Tie:
if not loadedAnimations[otherPlayer] then
	-- load the animation if it hasn't been loaded
	loadedAnimations[otherPlayer] = otherPlayer.Character.Humanoid.Animator:LoadAnimation(script.Animations.Handcuffed)
end
loadedAnimations[otherPlayer]:Play()

-- Untie:
if loadedAnimations[otherPlayer] then
	-- stop the animation if there is one
	-- (no need to stop the animation if it doesn't even exist)
	loadedAnimations[otherPlayer]:Stop()
end
2 Likes