Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Ragdoll script just making floating ball joints?

Hey! I've been learning about terrain generation lately and I finally got my script to work, and then I had the thought of making a physics game, anyway, I need ragdolls for that, and I'm not really good with joints, so help is appreciated!

My script is:

function ragdoll(player)
	local plr = game.Players[player]
	local character = plr.Character
	for _,motor in pairs(character:GetDescendants()) do
		if motor:IsA("Motor6D") then
			local at1 , at2 = Instance.new("Attachment", motor.Parent), Instance.new("Attachment", motor.Parent)
			at1.Name = "one" 
			at2.Name = "two"
			

			at1.CFrame = motor.Part0.CFrame
			at2.CFrame = motor.Part1.CFrame
			wait()
			local joint = Instance.new("BallSocketConstraint", motor.Parent)
			joint.Attachment0 = at1
			joint.Attachment1 = at2
			motor:Destroy()
			joint.Visible = true -- Only for testing
		end
	end



end

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		char.Humanoid.BreakJointsOnDeath = false
		char.Humanoid.Died:Connect(function()
			ragdoll(plr.Name)
			print("Died")
		end)
	end)
end)


Now, it is making ball joints, but they just float above my character and do nothing, they actually make my character fall apart?

Like I said help is appreciated, Thank you!

4 comments

0

How about dont add any attachments and find the attachment in the part0 and part1 like motor.Part0:FindFirstChild(motor.Name.. "Attachment") or motor.Part0:FindFirstChild(motor.Name.."RigAttachment")

1

Do the exact same with part1 too

1

Ill try that thanks man

0

I gave you a example on answers

1 answer

✓ Accepted answer

Here is a fixed version of your script that so far works for R15 (does some weird body poses LOL)

local function ragdoll(player)
	local character = player.Character or player.CharacterAdded:Wait()
	local humanoid = character.Humanoid or player.CharacterAdded:Wait()
	humanoid.BreakJointsOnDeath = false
	humanoid.Died:Connect(function()
		for i,motor in pairs(character:GetDescendants()) do
			if motor:IsA("Motor6D") then
				local ballsocket = Instance.new("BallSocketConstraint",motor.Parent)
				local at1 = motor.Part0:FindFirstChild(motor.Name.."Attachment") or motor.Part0:FindFirstChild(motor.Name.."RigAttachment")
				local at2 = motor.Part1:FindFirstChild(motor.Name.."Attachment") or motor.Part1:FindFirstChild(motor.Name.."RigAttachment")
				ballsocket.Attachment0,ballsocket.Attachment1 = at1,at2
				motor:Destroy()
				ballsocket.Visible = true
			end
		end
	end)
end
--[[
Attachment 1 is the original attachment on the character
Attachment 2 is also the original one on the character
so if i make these the ball constraints attachments
then it works fine!
--]]
ragdoll(game.Players:FindFirstChild(script.Parent.Name))

5 comments

0

If you set his RootPart.CanCollide to false after he dies, he will not do the cool poses

0

Humanoid root part? Alright thanks!

0

Hey thanks, this is exactly what I needed!

0

your welcome!

0

(this is from fm_trick but i just wrote it manually but with your variables)

This discussion is preserved as it was. New answers, comments, and votes are closed.