How do i make this script work on both client and server, and make it into r6?

Hello, after getting alot of support from NeutralEnergy, ive decided to make a repost to finish up what he has helped me with. The script itself works, just the client is buggy, for an example whenever a player touches the ragdoll, it stands up and starts spinning slowly…

i also want to make it into R6.

could anyone help? thanks!

the script goes into serverscriptservice

local players = game:GetService("Players")

local function makeRagDoll(doll)
	for index, joint in pairs (doll:GetDescendants()) do
		if joint:IsA("Motor6D") then
			local socket = Instance.new("BallSocketConstraint")
			local a1 = Instance.new("Attachment")
			local a2 = Instance.new("Attachment")
			a1.Parent = joint.Part0
			a2.Parent = joint.Part1
			socket.Parent = joint.Parent
			socket.Attachment0 = a1
			socket.Attachment1 = a2
			a1.CFrame = joint.C0
			a2.CFrame = joint.C1
			socket.LimitsEnabled = true
			socket.TwistLimitsEnabled = true
			joint:Destroy()
		end
	end
end

local function makeDup(char)

	char.Archivable = true
	local dChar = char:Clone()
	char.Archivable = true
	dChar.Parent = workspace

	for i, v in pairs(char:GetDescendants()) do
		if v:IsA("BasePart") then
			v.CanCollide = false
			v.Anchored = true
			v.Transparency = 1
		end
	end

	local healthScript = dChar:FindFirstChild("Health")
	if healthScript then
		healthScript.Enabled = false
	end

	if dChar then
		makeRagDoll(dChar)
	else
		warn("No Character Duplicate!")
	end
end

players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local hum = char:WaitForChild("Humanoid")
		hum.Died:Connect(function()
			print("Player Has Died!", player.Name)
			makeDup(char)
		end)
	end)
end)
1 Like

image
try this:

local players = game:GetService("Players")

local function makeRagDoll(doll)
	for index, joint in pairs (doll:GetDescendants()) do
		if joint:IsA("Motor6D") then
			local socket = Instance.new("BallSocketConstraint")
			local a1 = Instance.new("Attachment")
			local a2 = Instance.new("Attachment")
			a1.Parent = joint.Part0
			a2.Parent = joint.Part1
			socket.Parent = joint.Parent
			socket.Attachment0 = a1
			socket.Attachment1 = a2
			a1.CFrame = joint.C0
			a2.CFrame = joint.C1
			socket.LimitsEnabled = true
			socket.TwistLimitsEnabled = true
			joint:Destroy()
		end
	end
end

local function makeDup(char)

	char.Archivable = true
	local dChar = char:Clone()
	dChar.Archivable = true
	dChar.Parent = workspace

	for i, v:BasePart in pairs(char:GetDescendants()) do
		if v:IsA("BasePart") then
			v.CanCollide = false
			v.Anchored = true
			v.Transparency = 1
		end
	end
	
	for i, v:BasePart in pairs(dChar:GetDescendants()) do
		if v:IsA("BasePart") then
			v.Anchored = false
			v:SetNetworkOwner(nil)
		end
	end
	
	local hum:Humanoid = dChar:WaitForChild("Humanoid")
	hum.PlatformStand = true

	local healthScript = dChar:FindFirstChild("Health")
	if healthScript then
		healthScript.Enabled = false
	end

	if dChar then
		makeRagDoll(dChar)
	else
		warn("No Character Duplicate!")
	end
end

players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local hum:Humanoid = char:WaitForChild("Humanoid")
		hum.Died:Connect(function()
			print("Player Has Died!", player.Name)
			makeDup(char)
		end)
	end)
end)

i mean it works like the last one, except the arms and legs noclip through the ground. kind of like murder mystery 2, and whenever i touch the dead body it stands up, any fix to that?