Ragdoll script is for r15, how would i change this for R6? s

I found a ragdoll script in one of my games for r15, and i want to ask how would i change this for r6? I really dont expect anyone to figure out what is in here but if you do i would greatly appreciate it. Its a long script though:

local ragdoll = {}

local players = game:GetService"Players"
local physicsService = game:GetService"PhysicsService"
local repStorage = game:GetService"ReplicatedStorage"
local mainRemote = repStorage.Remotes:WaitForChild"Engine"

--physicsService:CreateCollisionGroup"Colliders"
--physicsService:CollisionGroupSetCollidable("Colliders","Colliders",false)



function DelayDestroy(obj,n)
	task.delay(n,function()
		obj:Destroy()
	end)
end
function getRandom(min,max,int)

	local rand = Random.new()
	return (min % 1 > 0 and rand:NextNumber(min,max) or rand:NextInteger(min,max))

end
function getNumInObj(obj,name)
	local i = 0
	for _,v in pairs(obj:GetChildren()) do
		if v.Name:find(name) then
			i += 1
		end
	end

	return i
end

local joint_Config = {
	LeftAnkle = {
		"Hinge";
		Properties = {
			LimitsEnabled = true;
			UpperAngle = 0; --5
			LowerAngle = -45; --5
			Restitution = 0;
		};
	};
	RightAnkle = {
		"Hinge";
		Properties = {
			LimitsEnabled = true;
			UpperAngle = 0; --5
			LowerAngle = -45; --5
			Restitution = 0;
		};
	};
	LeftKnee = {
		"Hinge";
		Properties = {
			LimitsEnabled = true;
			UpperAngle = -10;
			LowerAngle = -135;
			Restitution = 0;
		};
	};
	RightKnee = {
		"Hinge";
		Properties = {
			LimitsEnabled = true;
			UpperAngle = -10;
			LowerAngle = -135;
			Restitution = 0;
		};
	};
	LeftHip = {
		"BallSocket";
		Properties = {
			LimitsEnabled = true;
			TwistLimitsEnabled = true;
			MaxFrictionTorque = 0;
			UpperAngle = 40;
			TwistLowerAngle = -3;
			TwistUpperAngle = 3;
			Restitution = 0;
		};
	};
	RightHip = {
		"BallSocket";
		Properties = {
			LimitsEnabled = true;
			TwistLimitsEnabled = true;
			MaxFrictionTorque = 0;
			UpperAngle = 40; --30
			TwistLowerAngle = -3;
			TwistUpperAngle = 3;
			Restitution = 0;
		};
	};
	Waist = {
		"BallSocket";
		Properties = {
			LimitsEnabled = true;
			TwistLimitsEnabled = true;
			MaxFrictionTorque = 0;
			UpperAngle = 15;
			TwistLowerAngle = -1;
			TwistUpperAngle = 1;
			Restitution = 0;
		};
	};
	LeftShoulder = {
		"BallSocket";
		Properties = {
			LimitsEnabled = true;
			TwistLimitsEnabled = true;
			MaxFrictionTorque = 0;
			UpperAngle = 30;
			TwistLowerAngle = -30;
			TwistUpperAngle = 30;
			Restitution = 0;
		};
	};
	RightShoulder = {
		"BallSocket";
		Properties = {
			LimitsEnabled = true;
			TwistLimitsEnabled = true;
			MaxFrictionTorque = 0;
			UpperAngle = 30;
			TwistLowerAngle = -30;
			TwistUpperAngle = 30;
			Restitution = 0;
		};
	};
	LeftElbow = {
		"Hinge";
		Properties = {
			LimitsEnabled = true;
			UpperAngle = 135;
			LowerAngle = 0;
			Restitution = 0;
		};
	};
	RightElbow = {
		"Hinge";
		Properties = {
			LimitsEnabled = true;
			UpperAngle = 135;
			LowerAngle = 0;
			Restitution = 0;
		};
	};
	LeftWrist = {
		"Hinge";
		Properties = {
			LimitsEnabled = true;
			UpperAngle = 20; --5
			LowerAngle = -20; --5
			Restitution = 0;
		};
	};
	RightWrist = {
		"Hinge";
		Properties = {
			LimitsEnabled = true;
			UpperAngle = 20; --5
			LowerAngle = -20; --5
			Restitution = 0;
		};
	};
	Neck = {
		"BallSocket";
		Properties = {
			LimitsEnabled = true;
			TwistLimitsEnabled = true;
			MaxFrictionTorque = 0;
			UpperAngle = 0;
			TwistLowerAngle = -45;
			TwistUpperAngle = 45;
			Restitution = 0;
		};
	};
}

local randoms = {}

function ragdoll:reverseRagdoll(char)
	local plr = game:GetService"Players":GetPlayerFromCharacter(char)
	
	local userid = nil
	if plr  then
		userid = plr.UserId 
	else 
		if char and char.Parent  then
			local useridval = char:FindFirstChild("UserId")
			if useridval  then
				userid = useridval.Value
			end
		end
	end
	
	local random = randoms[userid]
	--[[local Stabilizer = Instance.new("BodyGyro") do
		Stabilizer.P = 100000
		Stabilizer.D = 500
		Stabilizer.MaxTorque = Vector3.new(10000, 0, 10000)
		Stabilizer.Parent = char.HumanoidRootPart
		game.Debris:AddItem(Stabilizer, .25)
	end]]
	
	--char.HumanoidRootPart.CFrame *= CFrame.new(0,3,0)
	--[[local rp = char:FindFirstChild("RagdollParts")
	if rp  then
		game.Debris:AddItem(rp,.15)
	end]]
--	print(utilityLib.getNumInObj(char,"RagdollParts"))
	--if utilityLib.getNumInObj(char,"RagdollParts") <= 1 then
	local rp = char:FindFirstChild("RagdollParts")
	if rp then rp:Destroy() end 
	
		local sockets = {}
		for _,v in pairs(char:GetDescendants()) do
			if v:IsA("Motor6D") then
				v.Enabled = true
			elseif v.Name == "RagdollSocket" .. random then 
				table.insert(sockets,v)
			elseif v.Name == "RagdollConstraint" .. random then 
				table.insert(sockets,v)
			elseif v.Parent.Name == "RagdollJoints" then
				v.Enabled = false
			end
		end

		for _,v in pairs(sockets) do v:Destroy() end

		for _,v in pairs(char:GetChildren()) do
			if (v:IsA"BasePart" or v:IsA"UnionOperation") then 
				if plr  then
					physicsService:SetPartCollisionGroup(v,"Characters")
				else 
					physicsService:SetPartCollisionGroup(v,"NPCs")
				end
			end
		end
		char.HumanoidRootPart.CanCollide = true
		char.HumanoidRootPart.Massless = false
		char.Humanoid.PlatformStand = false
		
		char.HumanoidRootPart.CFrame = CFrame.new(char.UpperTorso.Position + Vector3.new(0,2.5,0))
		if plr then
			mainRemote:FireClient(plr,"Ragdoll",false)
		else
			char.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Physics,false)
			char.Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp,true)
			char.Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
		end

	--end
end
function ragdoll:ragdollModel(char,dura,keepRagdoll,d2)
	if not char or (char and not char:FindFirstChild"HumanoidRootPart") or getNumInObj(char,"RagdollParts") >= 5 then return end
	
	
	
	char.HumanoidRootPart.CanCollide = false
	char.HumanoidRootPart.Massless = true

	local plr = game:GetService"Players":GetPlayerFromCharacter(char)
	local userid = nil 
	if plr  then
		userid = plr.UserId
	elseif char:FindFirstChild("UserId") then
		userid = char.UserId.Value
	else 
		userid = 50
	end
	
	local ragdollParts = Instance.new("Folder"); ragdollParts.Name = "RagdollParts"; ragdollParts.Parent = char
	game.Debris:AddItem(ragdollParts,d2)

	if char then
		local NoShiftTurn = Instance.new("BoolValue")
		NoShiftTurn.Name = "NoShiftTurn"
		NoShiftTurn.Parent = char
		DelayDestroy(NoShiftTurn,d2)
		
		char.HumanoidRootPart.RotVelocity,char.HumanoidRootPart.Velocity = Vector3.new(),Vector3.new()

		char.Humanoid.PlatformStand = true
	end

	local random = tostring(getRandom(-1000,1000) / 10)
	randoms[userid] = random
	for _,v in pairs(char:GetChildren()) do
		if (v:IsA"BasePart" or v:IsA"UnionOperation") then --and not v.Name:find"Torso" then
			physicsService:SetPartCollisionGroup(v,"Characters")
		end
	end
	
	if plr then
		if char.Humanoid.Health >0  then
			mainRemote:FireClient(plr,"Ragdoll",true)
		end
	else
		char.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Physics,true)
		char.Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp,false)
		char.Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
	end
	
	for _,v in pairs(char:GetChildren()) do
		local motor6d = v:FindFirstChildOfClass"Motor6D"
		if motor6d then --if v:IsA"Motor6D" then
			if motor6d.Name ~= "Root" and motor6d.Name ~= "RootJoint" and motor6d.Part0 and motor6d.Part1 then
				local att0 = Instance.new("Attachment")
				att0.Name = "RagdollSocket" .. random
				att0.CFrame = motor6d.C0
				att0.Parent = motor6d.Part0
				local att1 = Instance.new("Attachment")
				att1.Name = "RagdollSocket" .. random
				att1.CFrame = motor6d.C1
				att1.Parent = motor6d.Part1

				if joint_Config[motor6d.Name] then
					local socket = Instance.new("BallSocketConstraint")
					socket.Name = "RagdollConstraint" .. random
					socket.TwistLimitsEnabled = true
					socket.LimitsEnabled = true
					
					
					socket.Attachment0,socket.Attachment1 = att0,att1
					socket.Enabled = true
					socket.Parent = motor6d.Part0
				end

				if motor6d.Part1.Name:find"Foot" or motor6d.Part1.Name:find"Hand" or motor6d.Part1.Name:find"Head" or (motor6d.Part1.Name:find"UpperTorso" and not plr) then --or motor6d.Part1.Name:find"RootPart" then
					local collider = Instance.new("Part")
					collider.Anchored = false
					collider.Size = motor6d.Part1.Size / 2
					collider.CFrame = motor6d.Part1.CFrame
					collider.CanCollide = true
					collider.Transparency = 1

					local weld = Instance.new("ManualWeld")
					weld.Part0,weld.Part1 = motor6d.Part1,collider
					weld.C1 = weld.Part1.CFrame:ToObjectSpace(weld.Part0.CFrame)
					weld.Parent = collider
					collider.Parent = ragdollParts

					physicsService:SetPartCollisionGroup(motor6d.Part1,"collideParts")
					physicsService:SetPartCollisionGroup(collider,"collideParts")
				end

				motor6d.Enabled = false
			end
		end
		char.HumanoidRootPart.CanCollide = false 
		char.HumanoidRootPart.Massless = true
		char.HumanoidRootPart.RotVelocity,char.HumanoidRootPart.Velocity = Vector3.new(),Vector3.new()

	end

	if not keepRagdoll then
		task.delay(dura,function()
			if getNumInObj(char,"RagdollParts") <= 1 then
				local sockets = {}
				for _,v in pairs(char:GetDescendants()) do
					if v:IsA("Motor6D") then
						v.Enabled = true
					elseif v.Name == "RagdollSocket" .. random then 
						table.insert(sockets,v)
					elseif v.Name == "RagdollConstraint" .. random then 
						table.insert(sockets,v)
					elseif v.Parent.Name == "RagdollJoints" then
						v.Enabled = false
					end
				end

				for _,v in pairs(sockets) do v:Destroy() end

				for _,v in pairs(char:GetChildren()) do
					if (v:IsA"BasePart" or v:IsA"UnionOperation") then --and not v.Name:find"Torso" then
						if plr  then
							physicsService:SetPartCollisionGroup(v,"Characters")
						else 
							physicsService:SetPartCollisionGroup(v,"NPCs")
						end
					end
				end

				char.HumanoidRootPart.CanCollide = true
				char.HumanoidRootPart.Massless = false
				char.Humanoid.PlatformStand = false
				char.HumanoidRootPart.CFrame = CFrame.new(char.UpperTorso.Position + Vector3.new(0,2.5,0))
				
				if plr then
					if char.Humanoid.Health >0  then
						mainRemote:FireClient(plr,"Ragdoll",true)
					end
				else
					char.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Ragdoll,false)
					char.Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp,true)
					char.Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
				end
			end
		end)
	end
end



function ragdoll:reverseRagdoll2(char)
	
	local humanoid = char.Humanoid
	local plr = game.Players:GetPlayerFromCharacter(char)
	if plr  then
		mainRemote:FireClient(plr,"Ragdoll",false)
	else 
		humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
	end

end

function ragdoll:ragdollModel2(char,dura,keepRagdoll)
	if not char then return end 
	
	local humanoid = char.Humanoid
	local plr = game.Players:GetPlayerFromCharacter(char)
	if plr  then
		mainRemote:FireClient(plr,"Ragdoll",true)
	else 
		humanoid:ChangeState(Enum.HumanoidStateType.Physics)
	end
	
	if dura and dura ~= math.huge and not keepRagdoll then
		task.delay(dura,function()
			if plr then
				mainRemote:FireClient(plr,"Ragdoll",false)
			else 
				humanoid:ChangeState(Enum.HumanoidStateType.Physics)
			end

		end)
	end
end
return ragdoll
1 Like