Animation wont stop

I am using a while true do, and I have no idea how to stop it, I need to use a while true do for the rest of the script to work, if you could help that would be awesome its a roblox websling.
Code:

local statuses = {}
local webslingspeed = 2000
local tweens = game:GetService("TweenService")
local webzipspeed = 2500
local webreachspeed = .45
local radius = 3.5
local WebShootTime = 20
local WebShootSpeed = .2
local websize = 4
game:GetService("ReplicatedStorage").Web.OnServerEvent:Connect(function(plr, status, target, point, hand)
	if status == true then
		local char = plr.Character
		if char then
			local arm = char[hand.."Hand"] or char[hand.." Arm"]
			local armattachment = Instance.new("Attachment")

			armattachment.Parent = char.HumanoidRootPart
			armattachment.WorldPosition = char.HumanoidRootPart.Position

			local pointattachment = Instance.new("Attachment")
			pointattachment.Parent = target
			pointattachment.WorldPosition = point

			local bodyGyro = Instance.new("BodyGyro")
			bodyGyro.Parent = char.HumanoidRootPart
			bodyGyro.P = 1000
			bodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
			bodyGyro.D = 15

			local rope = Instance.new("RopeConstraint")
			local length = (arm.Position - point).Magnitude

			rope.Visible = false
			rope.Attachment0 = armattachment
			rope.Attachment1 = pointattachment
			rope.Parent = arm
			rope.Length = length
			rope.Color = BrickColor.new("White")
			rope.Restitution = .5

			task.wait()

			local fakeattach = Instance.new("Attachment")
			fakeattach.Parent = target
			fakeattach.WorldPosition = char[hand.."Hand"].Position

			local fakeattach2 = Instance.new("Attachment")
			fakeattach2.Parent = char[hand.."Hand"]
			fakeattach2.WorldPosition = char[hand.."Hand"].Position

			local beam = Instance.new("Beam")
			beam.Texture = "rbxassetid://8599205743"
			beam.TextureMode = Enum.TextureMode.Stretch
			beam.TextureSpeed = 0
			beam.TextureLength = .1
			beam.Transparency = NumberSequence.new(0)
			beam.LightEmission = 1
			beam.LightInfluence = 0
			beam.FaceCamera = true
			beam.Attachment0 = fakeattach2
			beam.Attachment1 = fakeattach
			beam.Width0 = 3
			beam.Width1 = 3
			beam.Parent = arm

			local bodyForce = Instance.new("BodyForce")
			bodyForce.Parent = char.HumanoidRootPart

			local animator = char.Humanoid:WaitForChild("Animator")
			local swing = animator:LoadAnimation(script:WaitForChild("Swing"))

			spawn(function()
				statuses[plr] = {armattachment, pointattachment, fakeattach, rope, bodyForce, bodyGyro, beam}
				local tween = tweens:Create(fakeattach, TweenInfo.new(webreachspeed), {WorldPosition = point})
				tween:Play()
				tween.Completed:Connect(function()
					beam.Attachment1 = pointattachment
				end)

				while true do

					if char.Humanoid then
						if statuses[plr] ~= nil then
							swing:Play()

							bodyGyro.CFrame =  CFrame.new(char.HumanoidRootPart.Position, char.HumanoidRootPart.Position + char.Humanoid.MoveDirection * 10)
							bodyForce.Force = Vector3.new(char.Humanoid.MoveDirection.X * webslingspeed, -webslingspeed / 10, webslingspeed / 5)

						else
							swing:Stop()
							tween:Cancel()

						end
					else
						swing:Stop()
						tween:Cancel()
						break
					end
					task.wait()
				end
			end)
		end


	elseif status == false then
		if statuses[plr] ~= nil then
			for _, v in pairs(statuses[plr]) do
				v:Destroy()
			end
			statuses[plr] = nil
		end
	end
end)

Hello there, you can stop a while loop by using “break”

Hey jakep, there are a couple of things that could be causing the problem here.
1.) The event you’ve connected the whole function to may be firing more than once. If this is the case, you have more than one animation being created with the same name, meaning that even if you stop one of them, the others continue. If this is the problem, you could fix it by taking the lines that define the animation being played (local animator = char.Humanoid:WaitForChild(“Animator”) and local swing = animator:LoadAnimation(script:WaitForChild(“Swing”)) and put them at the top of your code, before the main function.
2.) Since two out of three of the possibilities in your last if statement of your main function stop the animation, it is possible that the function is trying to stop an animation that was never played. Hopefully this isn’t the case, as you’d have to rework the whole function if it was.
3.) Thirdly, your while true do loop is inside of a function. That means if the function runs more than once, you have two or more while loops running potentially forever at the same time. This causes a whole lot of problems that you don’t want. To fix this, you’d just have to find a way to use a different loop structure, or maybe make there be a condition for the loop to run such that the condition is only met the first time it runs.

Hope this helps!