Im trying to develop a ragdoll script for r6. If the player’s hp reaches below .1, the player gets knocked and recovers in 15 seconds. This ragdoll works fine upon death, but does not work if the player is still alive. Does anybody know how to fix this?
local RagdollClientEvent = game.ReplicatedStorage:WaitForChild(“Events”).Ragdoll
local function unragdoll(player)
local character = player.Character
for _,v in pairs(character:GetDescendants()) do --unragdoll
if v:IsA(‘Motor6D’) then
v.Enabled = true
end
if v.Name == ‘BallSocketConstraint’ then
v:Destroy()
end
if v.Name == ‘Attachment’ then
v:Destroy()
end
end
RagdollClientEvent:FireClient(player)
end
local function ragdollplayer(player)
local character = player.Character
for _, v in pairs(character:GetDescendants()) do --ragdoll
if v:IsA(“Motor6D”) then
local a0, a1 = Instance.new(“Attachment”), Instance.new(“Attachment”)
a0.CFrame = v.C0
a1.CFrame = v.C1
a0.Parent = v.Part0
a1.Parent = v.Part1
local b = Instance.new(“BallSocketConstraint”)
b.Attachment0 = a0
b.Attachment1 = a1
b.Parent = v.Part0
v.Enabled = false
end
RagdollClientEvent:FireClient(player)
end
wait(15)
unragdoll(player)
end
local function LoadPlayer(player)
local char = player.Character or player.CharacterAdded:Wait()
local hum = char.Humanoid
hum.HealthChanged:connect(function()
if hum.Health < 1 then
hum.Health = math.clamp(.5,.01,1)
ragdollplayer(player)
end
end)
end
game.Players.PlayerAdded:connect(function(player)
LoadPlayer(player)
end)