Hello, I have this problem where when the player gets Ragdolled, after getting up he gets flung. Is there a simple way to fix this?
Here is my code:
local ragdoll = {}
local RunService = game:GetService("RunService")
local makeCollidable = {
"Right Arm",
"Left Arm",
"Right Leg",
"Left Leg"
}
function ragdoll.Start(character)
if character.Ragdoll.Value then return end
character.Ragdoll.Value = true
for i, joint in pairs(character:GetDescendants()) do
if joint:IsA("Motor6D") then
local socket = Instance.new("BallSocketConstraint")
local a0 = Instance.new("Attachment")
local a1 = Instance.new("Attachment")
a0.Parent = joint.Part0
a1.Parent = joint.Part1
socket.Parent = joint.Parent
socket.Attachment0 = a0
socket.Attachment1 = a1
a0.CFrame = joint.C0
a1.CFrame = joint.C1
socket.LimitsEnabled = true
socket.TwistLimitsEnabled = true
joint.Enabled = false
end
end
if not character:FindFirstChild('HumanoidRootPart').RootJoint.Enabled then
character:FindFirstChild('HumanoidRootPart').RootJoint.Enabled = true
end
character.Humanoid.WalkSpeed = 0
character.Humanoid.JumpPower = 0
character.Humanoid.PlatformStand = true
character.Humanoid.AutoRotate = false
for _, v in pairs(character:GetChildren()) do
if table.find(makeCollidable, v.Name) ~= nil then
local Stop = Instance.new("BoolValue", v)
Stop.Name = "stop"
local s = false
v.ChildRemoved:Connect(function(child)
if child.Name == "Stop" then
s = true
end
end)
local c
c = RunService.Stepped:Connect(function()
if s then
c:Disconnect()
return
end
v.CanCollide = true
end)
end
end
end
function ragdoll.Stop(character)
local hrp = character:FindFirstChild("HumanoidRootPart")
local hum = character:FindFirstChild("Humanoid")
if hum.Health <= 0 then return end
for _, v in pairs(character:GetChildren()) do
if table.find(makeCollidable, v.Name) ~= nil then
if v:FindFirstChild("Stop") then
v.Stop:Destroy()
end
end
end
hum.PlatformStand = false
for i, joint in pairs(character:GetDescendants()) do
if joint:IsA("BallSocketConstraint") then
joint:Destroy()
end
if joint:IsA("Motor6D") then
joint.Enabled = true
end
end
character.Ragdoll.Value = false
hum:ChangeState(Enum.HumanoidStateType.GettingUp)
hum.WalkSpeed = 16
hum.JumpPower = 50
hum.AutoRotate = true
end
return ragdoll