I am creating a roblox fighting game and want to incorporate a ragdoll system into the game to make it more impactful and fun. I went ahead and did this but I ran into a problem. Whenever knockback is applied to a ragdoll, the knockback is halted/reduced by a great amount. Can anybody help me with this? I’ve tried things like making the HumanoidRootPart massless but none of them have worked.
//Ragdoll Script
local function createConnection(char)
char.ChildAdded:Connect(function(child)
if child.Name == "Ragdoll" then
local success, err = pcall(function()
local stun = Instance.new("BoolValue", char); stun.Name = "Stun"
local iFrame = Instance.new("BoolValue", char); iFrame.Name = "IFrame"
local headCam = Instance.new("BoolValue"); headCam.Name = "HeadCamera"; headCam.Parent = char
local victimHRP = char:WaitForChild("HumanoidRootPart")
local plrCheck = game.Players:GetPlayerFromCharacter(char)
if not plrCheck then
victimHRP.Massless = true
char.Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
end
for _, v in pairs(char:GetDescendants()) do
if v:IsA("Motor6D") and v.Parent.Parent.Name ~= "Right Arm" and v.Parent.Parent.Name ~= "Left Arm" then
local socket = Instance.new("BallSocketConstraint", v.Parent)
local att0 = Instance.new("Attachment", v.Part0); att0.Name = "RagAtt"
local att1 = Instance.new("Attachment", v.Part1); att1.Name = "RagAtt"
att0.CFrame = v.C0
att1.CFrame = v.C1
socket.Attachment0 = att0
socket.Attachment1 = att1
socket.TwistLimitsEnabled = true
socket.LimitsEnabled = true
v.Enabled = false
end
end
end)
end
end)
char.ChildRemoved:Connect(function(child)
if child.Name == "Ragdoll" then
local success, err = pcall(function()
for _, v in pairs(char:GetChildren()) do
if v.Name == "Stun" or v.Name == "HeadCamera" then
v:Destroy()
elseif v.Name == "IFrame" then
game.Debris:AddItem(v, .5)
end
end
local plrCheck = game.Players:GetPlayerFromCharacter(char)
if not plrCheck then
if char then
if char.Humanoid then
if char.Humanoid.Health ~= 0 then
char.Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
char.HumanoidRootPart.Massless = false
end
end
end
end
for _, v in pairs(char:GetDescendants()) do
if v:IsA("Motor6D") and v.Parent.Parent.Name ~= "Right Arm" and v.Parent.Parent.Name ~= "Left Arm" then
v.Enabled = true
elseif v:IsA("BallSocketConstraint") or v.Name == "RagAtt" then
if v.Name ~= "RagAtt" then
v.Enabled = false
end
game.Debris:AddItem(v, .5)
end
end
end)
end
end)
end
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
createConnection(char)
end)
end)
workspace.DescendantAdded:Connect(function(child)
if child:IsA("Model") and child:FindFirstChild("Humanoid") then
createConnection(child)
end
end)
task.wait(5)
for _, v in pairs(workspace:GetDescendants()) do
if v:IsA("Model") and v:FindFirstChild("Humanoid") and not v:FindFirstChild("IsPlayer") then
createConnection(v)
end
end
//Knockback Script
module.applyVelocity = function(victim, facer, lookVectorStrength, upVectorStrength)
local hrp = victim:WaitForChild("HumanoidRootPart")
local facerHRP = facer:WaitForChild("HumanoidRootPart")
if victim:FindFirstChild("IsPlayer") then
--//For Player Knockback (Ignore this)
local vel = Instance.new("BoolValue"); vel.Name = "KBVelocity"
local facerValue = Instance.new("ObjectValue"); facerValue.Name = "Facer"; facerValue.Value = facer; facerValue.Parent = vel
local lookStrength = Instance.new("NumberValue"); lookStrength.Name = "LookVectorStrength"; lookStrength.Value = lookVectorStrength; lookStrength.Parent = vel
local upStrength = Instance.new("NumberValue"); upStrength.Name = "UpVectorStrength"; upStrength.Value = upVectorStrength; upStrength.Parent = vel
vel.Parent = victim
game.Debris:AddItem(vel, .1)
else
--//Actual Knockback
hrp.AssemblyLinearVelocity = facerHRP.CFrame.lookVector * lookVectorStrength + hrp.CFrame.UpVector * upVectorStrength
end
end