Flinging problem with Ragdoll

For as long as this ragdoll script of mine had been created, I’ve always had a flinging problem. Randomly, whenever you bumped into another character in my games including ragdoll, you would always be flung. I know this only occurs because of the ragdoll because when it was disabled, no fling occured.

I have no idea why this is happening. Maybe it is outdated now, or I’m doing something wrong?

Maybe it’s what I do in the script itself.

local function Glue(par, c0, c1, part0, part1, nam)
	local glue = Instance.new("Glue")
	glue.Name = nam
	glue.C0 = c0
	glue.C1 = c1
	glue.Part0 = part0
	glue.Part1 = part1
	glue.Parent = par
end

local function Joint(par, c0, c1, part0, part1, nam)
	local motor = Instance.new("Motor6D")
	motor.Name = nam
	motor.C0 = c0
	motor.C1 = c1
	motor.Part0 = part0
	motor.Part1 = part1
	motor.Parent = par
end

local function Touch(par, limb, cframe)
	local pr = Instance.new("Part")
	pr.Name = "touchy"
	pr.Size = Vector3.new(1, 1, 1)
	pr.Transparency = 1
	pr.CustomPhysicalProperties = PhysicalProperties.new(.55, .3, .5)
	pr.CanCollide = true
	pr.Anchored = false
	pr.Parent = par

	local w = Instance.new("Weld")
	w.Part0 = pr
	w.Part1 = limb
	w.C0 = cframe
	w.Parent = pr
end

local humanoid = character:WaitForChild("Humanoid")
local rag = character:FindFirstChild("Ragdoll", true)
local root = character:WaitForChild("HumanoidRootPart")

local rightArm = character["Right Arm"]
local leftArm = character["Left Arm"]
local rightLeg = character["Right Leg"]
local leftLeg = character["Left Leg"]

local rsC0 = CFrame.new(1.5 * 1, 0.5 * 1, 0, 0, 0, 1, 0, 1, 0, -1, 0, 0)
local rsC1 = CFrame.new(0, 0.5 * 1, 0, 0, 0, 1, 0, 1, 0, -1, 0, 0)
	
local lsC0 = CFrame.new(-1.5 * 1, 0.5 * 1, 0, 0, 0, -1, 0, 1, 0, 1, 0, 0)
local lsC1 = CFrame.new(0, 0.5 * 1, 0, 0, 0, -1, 0, 1, 0, 1, 0, 0)
	
local rhC0 = CFrame.new(0.5 * 1, -1 * 1, 0, 0, 0, 1, 0, 1, 0, -1, 0, 0)
local rhC1 = CFrame.new(0, 1 * 1, 0, 0, 0, 1, 0, 1, 0, -1, 0, 0)
	
local lhC0 = CFrame.new(-0.5 * 1, -1 * 1, 0, 0, 0, -1, 0, 1, 0, 1, 0, 0)
local lhC1 = CFrame.new(0 * 1, 1 * 1, 0, 0, 0, -1, 0, 1, 0, 1, 0, 0)
	
	character.Blocking.Value = false
	
	humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
	humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false)
	humanoid:SetStateEnabled(Enum.HumanoidStateType.Ragdoll, true)
	
	root.CanCollide = false
	root.Massless = true
	
	humanoid.PlatformStand = true
	
	if (root:FindFirstChild("OOF") and not root:FindFirstChild("OOF").IsPlaying) and humanoid.Health <= 1 then
		root.OOF:Play()
		root.OOF.TimePosition = .5
	end
		
	humanoid.AutoRotate = false
	
	if rightArm and torso:FindFirstChild("Right Shoulder") then
		torso:FindFirstChild("Right Shoulder"):Destroy()
		
		Glue(torso, rsC0, rsC1, torso, rightArm, "Right Shoulder")
		Touch(rightArm, rightArm, CFrame.new(0, .5, 0))
	end
	
	if leftArm and torso:FindFirstChild("Left Shoulder") then
		torso:FindFirstChild("Left Shoulder"):Destroy()
		
		Glue(torso, lsC0, lsC1, torso, leftArm, "Left Shoulder")
		Touch(leftArm, leftArm, CFrame.new(0, .5, 0))
	end
	
	if rightLeg and torso:FindFirstChild("Right Hip") then
		torso:FindFirstChild("Right Hip"):Destroy()
		
		Glue(torso, rhC0, rhC1, torso, rightLeg, "Right Hip")
		Touch(rightLeg, rightLeg, CFrame.new(0, .5, 0))
	end
	
	if leftLeg and torso:FindFirstChild("Left Hip") then
		torso:FindFirstChild("Left Hip"):Destroy()
		
		Glue(torso, lhC0, lhC1, torso,	leftLeg, "Left Hip")
		Touch(leftLeg, leftLeg, CFrame.new(0, .5, 0))
	end

-- After ragdoll is done
		
		Joint(torso, rsC0, rsC1, torso, rightArm, "Right Shoulder")
		
		if rightArm:FindFirstChild("touchy") then
			rightArm:FindFirstChild("touchy"):Destroy()
		end
	end
	
	if leftArm and torso:FindFirstChild("Left Shoulder") then
		torso:FindFirstChild("Left Shoulder"):Destroy()
		
		Joint(torso, lsC0, lsC1, torso, leftArm, "Left Shoulder")
		
		if leftArm:FindFirstChild("touchy") then
			leftArm:FindFirstChild("touchy"):Destroy()
		end
	end
	
	if rightLeg and torso:FindFirstChild("Right Hip") then
		torso:FindFirstChild("Right Hip"):Destroy()
		
		Joint(torso, rhC0, rhC1, torso, rightLeg, "Right Hip")
		
		if rightLeg:FindFirstChild("touchy") then
			rightLeg:FindFirstChild("touchy"):Destroy()
		end
	end
	
	if leftLeg and torso:FindFirstChild("Left Hip") then
		torso:FindFirstChild("Left Hip"):Destroy()
		
		Joint(torso, lhC0, lhC1, torso,	leftLeg, "Left Hip")
		
		if leftLeg:FindFirstChild("touchy") then
			leftLeg:FindFirstChild("touchy"):Destroy()
		end
	end
	
	humanoid.PlatformStand = false
	humanoid.AutoRotate = true
	root.Massless = false
	
	humanoid:SetStateEnabled(Enum.HumanoidStateType.Ragdoll, false)
	humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, false)
	humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, true)
	
	spawn(function()
		for i = 1, 20 do
			root.Velocity = Vector3.new(0, 0, 0)
			wait(.05)
		end
	end)
	
	local bg = Instance.new("BodyGyro")
	bg.P = 1000000
	bg.D = 500
	bg.MaxTorque = Vector3.new(math.huge, 0, math.huge)
    bg.Parent = root
    game.Debris:AddItem(bg, .1)

	root.CanCollide = true

Please, tell me what I’m doing wrong. This is a crucial point of my game, as ragdoll is used almost everytime an action is performed.

4 Likes
local bg = Instance.new("BodyGyro")
bg.P = 1000000
bg.D = 500
bg.MaxTorque = Vector3.new(math.huge, 0, math.huge)
bg.Parent = root
game.Debris:AddItem(bg, .1)

Why is the max torque infinite? Maybe that is what causes flings?

That’s actually what I use to prevent the character from just staying on the ground after a ragdoll is undone. They are stuck on the ground momentarily, and I have to use that to make that not happen.

Ah, okay. Maybe you could add a body position that lifts the character up a bit, so that the gyro doesn’t have to be as strong?

Maybe, but that won’t fix my initial problem.

I’ve remade your script and it seems to work fine. :slight_smile:

function Glue(Part, C0, C1, Part0, Part1, Name)
	local Glue = Instance.new("Glue") do
		Glue.Name = Name
		Glue.C0 = C0
		Glue.C1 = C1
		Glue.Part0 = Part0
		Glue.Part1 = Part1
		Glue.Parent = Part
	end
end

function Joint(Part, C0, C1, Part0, Part1, Name)
	local Motor6D = Instance.new("Motor6D") do
		Motor6D.Name = Name
		Motor6D.C0 = C0
		Motor6D.C1 = C1
		Motor6D.Part0 = Part0
		Motor6D.Part1 = Part1
		Motor6D.Parent = Part
	end
end

function Touch(Part, Limb, WeldCFrame)
	local TouchPart = Instance.new("Part") do
		TouchPart.Name = "TouchPart"
		TouchPart.Size = Vector3.new(1, 1, 1)
		TouchPart.Transparency = 1
		TouchPart.CustomPhysicalProperties = PhysicalProperties.new(.55, .3, .5)
		TouchPart.CanCollide = true
		TouchPart.Anchored = false
		TouchPart.Parent = Part
	end

	local Weld = Instance.new("Weld") do
		Weld.Part0 = TouchPart
		Weld.Part1 = Limb
		Weld.C0 = WeldCFrame
		Weld.Parent = TouchPart
	end
end

Character = script.Parent

Humanoid = Character:WaitForChild("Humanoid")
HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")

Torso = Character:WaitForChild("Torso")
LeftArm = Character:WaitForChild("Left Arm")
RightArm = Character:WaitForChild("Right Arm")
LeftLeg = Character:WaitForChild("Left Leg")
RightLeg = Character:WaitForChild("Right Leg")

Ragdolled = Instance.new("BoolValue") do
	Ragdolled.Name = "Ragdolled"
	Ragdolled.Parent = Character
end
Blocking = Instance.new("BoolValue") do
	Blocking.Name = "Blocking"
	Blocking.Parent = Character
end

LeftArmC0 = CFrame.new(-1.5 * 1, 0.5 * 1, 0, 0, 0, -1, 0, 1, 0, 1, 0, 0)
LeftArmC1 = CFrame.new(0, 0.5 * 1, 0, 0, 0, -1, 0, 1, 0, 1, 0, 0)

RightArmC0 = CFrame.new(1.5 * 1, 0.5 * 1, 0, 0, 0, 1, 0, 1, 0, -1, 0, 0)
RightArmC1 = CFrame.new(0, 0.5 * 1, 0, 0, 0, 1, 0, 1, 0, -1, 0, 0)
	
LeftLegC0 = CFrame.new(-0.5 * 1, -1 * 1, 0, 0, 0, -1, 0, 1, 0, 1, 0, 0)
LeftLegC1 = CFrame.new(0 * 1, 1 * 1, 0, 0, 0, -1, 0, 1, 0, 1, 0, 0)

RightLegC0 = CFrame.new(0.5 * 1, -1 * 1, 0, 0, 0, 1, 0, 1, 0, -1, 0, 0)
RightLegC1 = CFrame.new(0, 1 * 1, 0, 0, 0, 1, 0, 1, 0, -1, 0, 0)

function Ragdollify()
	if Ragdolled.Value then return end
	Ragdolled.Value = true
	Blocking.Value = false
		
	Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
	Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false)
	Humanoid:SetStateEnabled(Enum.HumanoidStateType.Ragdoll, true)
		
	HumanoidRootPart.CanCollide = false
	HumanoidRootPart.Massless = true
	
	Humanoid.PlatformStand = true
	
	if (HumanoidRootPart:FindFirstChild("OOF") and not HumanoidRootPart:FindFirstChild("OOF").IsPlaying) and HumanoidRootPart.Health <= 1 then
		HumanoidRootPart.OOF:Play()
		HumanoidRootPart.OOF.TimePosition = .5
	end
		
	Humanoid.AutoRotate = false
	
	if LeftArm and Torso:FindFirstChild("Left Shoulder") then
		Torso:FindFirstChild("Left Shoulder"):Destroy()
		
		Glue(Torso, LeftArmC0, LeftArmC1, Torso, LeftArm, "Left Shoulder")
		Touch(LeftArm, LeftArm, CFrame.new(0, .5, 0))
	end
	
	if RightArm and Torso:FindFirstChild("Right Shoulder") then
		Torso:FindFirstChild("Right Shoulder"):Destroy()
		
		Glue(Torso, RightArmC0, RightArmC1, Torso, RightArm, "Right Shoulder")
		Touch(RightArm, RightArm, CFrame.new(0, .5, 0))
	end
	
	if LeftLeg and Torso:FindFirstChild("Left Hip") then
		Torso:FindFirstChild("Left Hip"):Destroy()
		
		Glue(Torso, LeftLegC0, LeftLegC1, Torso, LeftLeg, "Left Hip")
		Touch(LeftLeg, LeftLeg, CFrame.new(0, .5, 0))
	end
	
	if RightLeg and Torso:FindFirstChild("Right Hip") then
		Torso:FindFirstChild("Right Hip"):Destroy()
		
		Glue(Torso, RightLegC0, RightLegC1, Torso, RightLeg, "Right Hip")
		Touch(RightLeg, RightLeg, CFrame.new(0, .5, 0))
	end
end

function Unragdollify()
	for i, v in ipairs(Character:GetDescendants()) do
		if v.Name == "TouchPart" then
			v:Destroy()
		end
	end
	
	if LeftArm and Torso:FindFirstChild("Left Shoulder") then
		Torso:FindFirstChild("Left Shoulder"):Destroy()
		
		Joint(Torso, LeftArmC0, LeftArmC1, Torso, LeftArm, "Left Shoulder")
	end
	
	if RightArm and Torso:FindFirstChild("Right Shoulder") then
		Torso:FindFirstChild("Right Shoulder"):Destroy()
		
		Joint(Torso, RightArmC0, RightArmC1, Torso, RightArm, "Right Shoulder")
	end
	
	if LeftLeg and Torso:FindFirstChild("Left Hip") then
		Torso:FindFirstChild("Left Hip"):Destroy()
		
		Joint(Torso, LeftLegC0, LeftLegC1, Torso, LeftLeg, "Left Hip")
	end
	
	if RightLeg and Torso:FindFirstChild("Right Hip") then
		Torso:FindFirstChild("Right Hip"):Destroy()
		
		Joint(Torso, RightLegC0, RightLegC1, Torso, RightLeg, "Right Hip")
	end
	
	Humanoid.PlatformStand = false
	Humanoid.AutoRotate = true
	HumanoidRootPart.Massless = false
	HumanoidRootPart.CanCollide = true
	
	Humanoid:SetStateEnabled(Enum.HumanoidStateType.Ragdoll, false)
	Humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, false)
	Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, true)
	
	local FloatThing = Instance.new("BodyPosition") do
		FloatThing.Position = HumanoidRootPart.Position + Vector3.new(0, 2, 0)
		FloatThing.Parent = HumanoidRootPart
		game.Debris:AddItem(FloatThing, 0.25)
	end
	
	local Stabilizer = Instance.new("BodyGyro") do
		Stabilizer.P = 1000000
		Stabilizer.D = 500
		Stabilizer.MaxTorque = Vector3.new(10000, 0, 10000)
	    Stabilizer.Parent = HumanoidRootPart
	    game.Debris:AddItem(Stabilizer, .25)
	end
	
	Ragdolled.Value = false
end


-- Ragdoll events here:
Player = game:GetService("Players"):GetPlayerFromCharacter(Character)

ReplicatedStorage = game:GetService("ReplicatedStorage")

RagdollifyEvent = ReplicatedStorage:WaitForChild("Ragdollify", 5)
if not RagdollifyEvent then
	RagdollifyEvent = Instance.new("BindableEvent") do
		RagdollifyEvent.Name = "Ragdollify"
		RagdollifyEvent.Parent = ReplicatedStorage
	end
end

UnragdollifyEvent = ReplicatedStorage:WaitForChild("Unragdollify", 5)
if not UnragdollifyEvent then
	UnragdollifyEvent = Instance.new("BindableEvent") do
		UnragdollifyEvent.Name = "Unragdollify"
		UnragdollifyEvent.Parent = ReplicatedStorage
	end
end

RagdollifyEvent.Event:Connect(function(PlayerToAffect)
	if PlayerToAffect ~= Player then return end
	Ragdollify()
end)
UnragdollifyEvent.Event:Connect(function(PlayerToAffect)
	if PlayerToAffect ~= Player then return end
	Unragdollify()
end)


-- Example code to trigger ragdoll:
wait(5)
RagdollifyEvent:Fire(game.Players:GetPlayers()[1])
wait(5)
UnragdollifyEvent:Fire(game.Players:GetPlayers()[1])

As a side note, this script is intended to be inserted into StarterCharacterScripts, found in the StarterPlayer folder.

3 Likes

Thanks. I’ll test this out later with a friend!

Okay, I have tested it with a friend, and I am pleased at your corrections of my script. Characters now no longer fling across the map when colliding with eachother. However, I still have found a small problem. I am not trying to be picky, just pointing it out.

In this gif here, I use a move that ragdolls a player. After he gets up and touches me, I slightly go into the air, but come back down shortly after.
https://gyazo.com/14d1970c3353a1593c63b1812d6fbe18
This could be a potential problem due to fall damage being in my game.

1 Like

Ah, ok.

  1. I just did some improvements and edits that seemed alrighty to me;
  2. It may be the duration of the body forces being in the HumanoidRootPart, or one of your scripts is doing something unexpected. (It’s probably just my aproach but i don’t have anyone to test on)

I see. Well, if you get someone to test it on, please, inform me of your findings.

					Ragdollify:Fire(game.Players:GetPlayers()[1])
					wait(5)
					Unragdollify:Fire(game.Players:GetPlayers()[1])

It said Fire Not Apart of RemoteEvent

What did I do wrong

Oh, the code i made was based off of BindableEvents, those make use of :Fire and .Event

Try this if you are using RemoteEvents;

Ragdollify:FireClient(game.Players:GetPlayers()[1])
wait(5)
Unragdollify:FireClient(game.Players:GetPlayers()[1])