How to delete r15 motors properly?

Hello, i hope everyone is doing well.

I am working on a movement system which includes physical animations and for that i need a R15 ragdoll as soon as the player spawn.

Problem is: the ragdoll spawning behavior is literally random

Sometimes it spawns with joints:
bruh
even though i am explicitly deleting them on the ragdoll creating function

for i,v in pairs(c:GetDescendants()) do 
		if v:IsA("Motor6D") and v.Name ~= "RootJoint" then 
			local at = it("Attachment",v.Part0)
			at.Name = ("attacher")
			at.Position = v.C0.p 
			local at2 = it("Attachment",v.Part1)
			at2.Name = ("attacher2")
			at2.Position = v.C1.p 
			local b = it("BallSocketConstraint",v.Parent)
			b.LimitsEnabled = true
			b.Attachment0 = at 
			b.Attachment1 = at2
			b.Name = "bsc"
			table.insert(partprop,v.Name)
			table.insert(partprop,v.Parent)
			table.insert(partprop,v.Part0)
			table.insert(partprop,v.Part1)
			table.insert(partprop,v.C0)
			table.insert(partprop,v.C1)
			v:Destroy()
		end
	end 
v:Destroy()

^^^^
and sometimes it just works???
not bruh

The ragdolls move using alignposition and alignorientation to their puppet respective bodyparts, but there’s no way those are causing this problem.
what am i doing wrong?
Thanks in advance.
Note: the ragdolls are literally clones of the player’s character.

Load an animation and then get rid of them

Hello, sorry for the late answer.
I tried what you told me to do although nothing happened it’s still the same problem:
bruh2

code changed to:

function ragdoll(c)
	local hu=c.Humanoid
	local a=hu:LoadAnimation(script:WaitForChild("AimingL"))
	local rval = it("BoolValue",c)
	rval.Name="Ragdolled"
	rval.Value = true
	local fol = it("Folder",c)
	fol.Name = "ragdparts"
	if c:FindFirstChild("Humanoid") then c.Humanoid.PlatformStand = true end
	for i=1,2 do 
		for i,v in pairs(c:GetDescendants()) do 
			if v.Name == "attacher" or v.Name == "attacher2" or v.Name == "bsc" or v.Name == "colpart" then 
				v:Destroy()
			end 
		end 
	end
	for i,v in pairs(c:GetChildren()) do 
		if v:IsA("BasePart") then 
			PhysicsService:SetPartCollisionGroup(v,ragroup)
			v.Massless = true
			cpart(v)
		end 
	end
	for i,v in pairs(c:GetDescendants()) do 
		if v:IsA("Motor6D") and v.Name ~= "RootJoint" then 
			local at = it("Attachment",v.Part0)
			at.Name = ("attacher")
			at.Position = v.C0.p 
			local at2 = it("Attachment",v.Part1)
			at2.Name = ("attacher2")
			at2.Position = v.C1.p 
			local b = it("BallSocketConstraint",v.Parent)
			b.LimitsEnabled = true
			b.Attachment0 = at 
			b.Attachment1 = at2
			b.Name = "bsc"
			table.insert(partprop,v.Name)
			table.insert(partprop,v.Parent)
			table.insert(partprop,v.Part0)
			table.insert(partprop,v.Part1)
			table.insert(partprop,v.C0)
			table.insert(partprop,v.C1)
			v:Destroy()
		end
	end 
end 

Try adding rope when the motors/attachments are destroyed

Already am, using Ball in socket constraints, though no problems, i just found the solution.
I have no idea why, but the problem is actually an inconsistency with server–>client .
Even though the motors are being deleted on the server, they still persist on the client
As seen here on client:
omega bruh

(notice the several joints, "LeftFoot
VS on the server:
bruh why

This makes literally no sense in my head, considering that things deleted on the server shouldn’t persist on the client?

Oh well

Problem’s easy to solve now, i can just clone this local script on the character after the motors are deleted on the server

local body=script.Parent:WaitForChild("Body")


local Motors={}
for _,v in pairs(body:GetDescendants()) do 
	if v:IsA("Motor6D") then 
		table.insert(Motors,v)
	end
end

print("Found a total of: "..#Motors.." Client sided motors")

print("Removing. . .")


for i=1,#Motors do 
	print("Removed "..Motors[i].Name)
	Motors[i]:Destroy()
end

print("Successfully cleaned client motors")

and boom!
working

Even though i ended up solving this by myself, thank you very much for taking the time to help getting to a solution.

1 Like