--[[INFORMATION------------------------------------------------[[
	ARTFVL's R15 Ragdoll (as seen in Ragdoll Testing v3)
	Updated: November 20th 2021
	
	CREDIT ME FOR USING THIS RAGDOLL SCRIPT.
	
	Credits:
		R15 RAGDOLL WAS CREATED BY ARTFVL
		ORIGINALLY BASED ON ECHOREAPER'S R15 RAGDOLL
--]]
-----------------------------------------------------------]]

local module = {}

module.KillHumanoid = function(Humanoid)
	for i = 1, 1 do
		Humanoid.Health = 1
		Humanoid.Health = -1
	end
end

module.DestroyMotors = function(Table)
	for _, Motor in pairs(Table) do
		Motor:Destroy()
		Motor = nil
	end
end

module.KillRagdolls = function()
	local function KillRagdoll(Inst)
		if string.match(Inst.Name,"'s Ragdoll") then
			local hum = Inst:WaitForChild("Humanoid")
			module.KillHumanoid(hum)
		end
	end
	
	for _,v in pairs(workspace:GetChildren()) do
		spawn(function() KillRagdoll(v) end)
	end

	workspace.ChildAdded:Connect(function(child)
		KillRagdoll(child)
	end)
end

module.RunService = game:GetService("RunService")

module.ApplyZeroVelocity = function(Character)
	for _,v in pairs(Character:GetDescendants()) do
		if v:IsA("BasePart") then
			v.AssemblyLinearVelocity = Vector3.new(0,0,0)
			v.AssemblyAngularVelocity = Vector3.new(0,0,0)
		end
	end
end
module.KillVelocity = function(Character)
	pcall(module.ApplyZeroVelocity,Character)
	module.RunService.Stepped:wait()
	pcall(module.ApplyZeroVelocity,Character)
end

return module
