Player flings around when unragdolling

When the player gets up after I ragdoll them sometimes they fling around and it kinda ruins the game

Here’s my script

HitEvt.OnServerEvent:Connect(function(player, hithum, ToolModule, tool, Uses)
	local Module = require(ToolModule)

	if not hithum then return end

	hithum:TakeDamage(Module.Damage)
	
	-----------------------------
	
	if Module.Stun then
		local character = hithum.Parent
		if character and character:IsA("Model") then
			local humanoid = character:FindFirstChildOfClass("Humanoid")
			local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")

			if humanoid then
				humanoid:UnequipTools()
				humanoid.PlatformStand = true
				humanoid.AutoRotate = false
			end

			for _, joint in pairs(character:GetDescendants()) do
				if joint:IsA("Motor6D") and joint.Part0 and joint.Part1 then
					joint.Enabled = false

					local attach0 = Instance.new("Attachment", joint.Part0)
					local attach1 = Instance.new("Attachment", joint.Part1)
					attach0.CFrame = joint.C0
					attach1.CFrame = joint.C1

					local socket = Instance.new("BallSocketConstraint")
					socket.Attachment0 = attach0
					socket.Attachment1 = attach1
					socket.LimitsEnabled = true
					socket.TwistLimitsEnabled = true
					socket.Parent = joint.Parent

					local ghostPart = Instance.new("Part")
					ghostPart.Size = Vector3.new(0.95, 0.95, 0.95)
					ghostPart.Transparency = 1
					ghostPart.CanCollide = true
					ghostPart.CanQuery = false
					ghostPart.CanTouch = false
					ghostPart.Anchored = false
					ghostPart.Name = "GhostLimbPart"
					ghostPart.Parent = character
					ghostPart.CFrame = joint.Part1.CFrame
					ghostPart.CollisionGroup="UncollidableProps"

					local weld = Instance.new("WeldConstraint")
					weld.Part0 = joint.Part1
					weld.Part1 = ghostPart
					weld.Parent = ghostPart
				end
			end

			local targetPlayer = Players:GetPlayerFromCharacter(character)
			if targetPlayer then
				
				RagdollEvt:FireClient(targetPlayer, Module.StunTme)
			end

			task.delay(Module.StunTme, function()
				for _, obj in pairs(character:GetDescendants()) do
					if obj:IsA("Motor6D") then
						obj.Enabled = true
					elseif obj:IsA("BallSocketConstraint") or obj:IsA("Attachment") or obj.Name == "GhostLimbPart" then
						obj:Destroy()
					end
				end

				if humanoid then
					humanoid.PlatformStand = false
					humanoid.AutoRotate = true
					humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
				end
			end)
		end
	end
end)

What did I do wrong?

I did call

humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)

Can I make a suggestion if all the players have the chance to ragdoll in the game?

Instead of creating all your Attachments and BallSocketConstraints each time why not create them in the player when they join the game? That way you’d only have to go through the BallSocketConstraints and make them Active true or false depending if Module.Stun is true.
Then create all your ghostParts (and make them Massless = true) and when Module.Stun is true just toggle them between CanCollide true and false.

With your way you could be having 2 issues.

  • Your ghostParts aren’t Massless so they affect Humanoid physics.
  • It might be that you are disabling the joint first, then creating the BallSockets, then the ghostParts, setting all their Properties, then Parenting them. It might only take 1 frame to do all of this, but with Roblox physics that can be an issue. If you have to use this method rather than my suggestion above try making your BallSockets Active before making the joint.Enabled = false so the limb is never unattached in one way or another.
1 Like

@Kriegtical

if i understand Correctly you only called this on the server. You need to send a remote event and do it locally. I think. not sure (didnt mean to reply to you scottifly dont know how to undo. that first time posting sry)

I think you can edit the ‘reply to’ person in your post.
Or just do @Kriegtical so they see your reply.

I’ll try this and report back prolly tomorrow, I can’t test that atm, but that MIGHT be the issue cause I didnt set the part to massless

1 Like