Hello Developers!
I’ve made a weapon with a ragdoll system where whenever an humanoid gets hit by the weapon, the said humanoid will be damaged and be ragdolled for a few seconds. The only issue is that I made it so that whenever the humanoid gets ragdolled, it’s body parts doesn’t clip into the ground. But if it dies, then the body parts clip into the ground.
This is the weapon script: (Sorry if the script seems a bit sloppy, I’m still kinda new to Roblox scripting.)
--//Tool\\--
local Wielder = nil
local FireExtinguisher = script.Parent
--//Services\\--
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
--//Connections\\--
local Debounce = false
local CanDamage = false
FireExtinguisher.AttackEvent.OnServerEvent:Connect(function(Player)
local SwingAnim = Player.Character.Humanoid:WaitForChild("Animator"):LoadAnimation(FireExtinguisher.Swing)
SwingAnim:Play()
local PreviousSpeed = Player.Character.Humanoid.WalkSpeed
Player.Character.Humanoid.WalkSpeed = 25
local FunnyDemoKnightJoke = math.random(1,8)
if FunnyDemoKnightJoke == 8 then
script:WaitForChild("Charge"):Play()
FireExtinguisher.BodyAttach.ChargeEffect.Enabled = true
Player.Character.Humanoid.WalkSpeed = math.random(33,45)
end
task.wait(0.30)
CanDamage = true
Player.Character.Humanoid.WalkSpeed = 8
FireExtinguisher.BodyAttach.ChargeEffect.Enabled = false
script:WaitForChild("Charge"):Stop()
script:WaitForChild("Swing"):Play()
FireExtinguisher.BodyAttach.Touched:Connect(function(OnHit)
local Player = Players:GetPlayerFromCharacter(OnHit.Parent)
if Player then
if Player.Team ~= Wielder.Team.Name then
local Humanoid = OnHit.Parent:FindFirstChildWhichIsA("Humanoid")
if Humanoid and Humanoid.Health >= 1 and CanDamage == true then
Humanoid:TakeDamage(55)
script:WaitForChild("Hit"):Play()
Humanoid.PlatformStand = true
Humanoid:ChangeState(Enum.HumanoidStateType.Ragdoll)
Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false)
for _, Joints in pairs(OnHit.Parent:GetDescendants()) do
if Joints:IsA("Motor6D") then
local BallSocket = Instance.new("BallSocketConstraint",Joints.Parent)
local A1 = Instance.new("Attachment",Joints.Part0)
local A2 = Instance.new("Attachment",Joints.Part1)
BallSocket.Attachment0 = A1
BallSocket.Attachment1 = A2
A1.CFrame = Joints.C0
A2.CFrame = Joints.C1
BallSocket.LimitsEnabled = true
BallSocket.TwistUpperAngle = true
Joints.Enabled = false
end
end
CanDamage = false
task.wait(3)
for _, Joints in pairs(OnHit.Parent:GetDescendants()) do
if Joints:IsA("BallSocketConstraint") then
Joints:Destroy()
end
if Joints:IsA("Motor6D") then
Joints.Enabled = true
end
end
Humanoid.PlatformStand = false
end
end
elseif not Player then
local Humanoid = OnHit.Parent:FindFirstChildWhichIsA("Humanoid")
if Humanoid and Humanoid.Health >= 1 and CanDamage == true then
Humanoid:TakeDamage(55)
script:WaitForChild("Hit"):Play()
Humanoid.PlatformStand = true
Humanoid:ChangeState(Enum.HumanoidStateType.Ragdoll)
Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false)
for _, Joints in pairs(OnHit.Parent:GetDescendants()) do
if Joints:IsA("Motor6D") then
local BallSocket = Instance.new("BallSocketConstraint",Joints.Parent)
local A1 = Instance.new("Attachment",Joints.Part0)
local A2 = Instance.new("Attachment",Joints.Part1)
BallSocket.Attachment0 = A1
BallSocket.Attachment1 = A2
A1.CFrame = Joints.C0
A2.CFrame = Joints.C1
BallSocket.LimitsEnabled = true
BallSocket.TwistUpperAngle = true
Joints.Enabled = false
end
end
CanDamage = false
task.wait(3)
for _, Joints in pairs(OnHit.Parent:GetDescendants()) do
if Joints:IsA("BallSocketConstraint") then
Joints:Destroy()
end
if Joints:IsA("Motor6D") then
Joints.Enabled = true
end
end
Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, true)
Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
Humanoid.PlatformStand = false
end
end
end)
SwingAnim.Stopped:Wait()
CanDamage = false
task.wait(0.5)
Player.Character.Humanoid.WalkSpeed = PreviousSpeed
end)