Im trying to make a client-sided ragdoll system, so far everything works but my code is having trouble deleting a cloned characters Motor6D’s
The following is the Ragdoll code
local function ragdoll(char)
char:WaitForChild("Humanoid").AutoRotate = false
for _, part in char:GetDescendants() do
if part:IsA("Motor6D") then
local socket = Instance.new("BallSocketConstraint")
local a1 = Instance.new("Attachment")
local a2 = Instance.new("Attachment")
a1.Parent = part.Part0
a2.Parent = part.Part1
socket.Parent = part.Parent
socket.Attachment0 = a1
socket.Attachment1 = a2
a1.CFrame = part.c0
a2.CFrame = part.c1
socket.LimitsEnabled = true
socket.TwistLimitsEnabled = true
socket.MaxFrictionTorque = 0
print("FoundMotor6d")
part:Destroy()
end
end
char.HumanoidRootPart:ApplyImpulse(Vector3.new(math.random(-RAGDOLL_MAGNITUDE, RAGDOLL_MAGNITUDE), math.random(RAGDOLL_MAGNITUDE), math.random(-RAGDOLL_MAGNITUDE, RAGDOLL_MAGNITUDE)))
end
When I clone the character using the following code
Remotes.Ragdoll.OnClientEvent:Connect(function(plr)
if plr == game.Players.LocalPlayer then
ragdoll(character)
return
end
if plr.Character then
plr.Character.Archivable = true
else
return
end
local ClonedCharacter = plr.Character:Clone()
ClonedCharacter.Parent = workspace
ClonedCharacter:PivotTo(plr.Character.PrimaryPart.CFrame)
plr.Character:Destroy()
ragdoll(ClonedCharacter)
end)
The module prints that it found 16 Motor6D and then launches the player but the player doesn’t end up ragdolling and is instead stiff.
Looking into the ragdoll model the motor6D’s are still there and so are the new ball socket constraints.
I tried adding a wait in between the character being cloned and the ragdoll function being called and the system worked perfectly except for there is a noticeable 1 second delay.
Now I bet I could solve this issue by cloning every character once a player respawns and sort of caching it or just setting a fixed delay and kinda hoping the system will work 100% of the time.
But I wanted to know if there was an easier way to solve this, or if there is maybe a property I can enable.