Hi guys! I am trying to make a module function to ragdoll the player, but I get this weird effect if I try to do it when the character is alive.
When player dies:
When player is alive:
Ragdoll script
local module = {}
function module.Ragdoll(char) -- Defines function
if not char:FindFirstChild("Humanoid") then -- If does not contain a humanoid
warn("Attempted to ragdoll " .. tostring(char) .. ", which is not a character") -- Warn it is not a character
end
for i, object in char:GetDescendants() do -- Get every class Motor6D in the character
if object:IsA("Motor6D") then
local attachment0 = Instance.new("Attachment") -- Create an attachment
local attachment1 = Instance.new("Attachment") -- Create an another attachment
attachment0.CFrame = object.C0 -- Sets attachment0 to the Motor6D CFrame 0
attachment1.CFrame = object.C1 -- Sets attachment1 to the Motor6D CFrame 1
attachment0.Parent = object.Part0 -- Sets attachment0 parent to the Motor6D Part 0
attachment1.Parent = object.Part1 -- Sets attachment1 parent to the Motor6D Part 1
attachment0.Name = "RagdollAttachment0" -- Names attachment0
attachment1.Name = "RagdollAttachment1" -- Names attachment1
local ballsocketconstraint = Instance.new("BallSocketConstraint") -- Creates a BallSocketConstraint
ballsocketconstraint.Attachment0 = attachment0 -- Sets the contraint's attachment0 to attachment0
ballsocketconstraint.Attachment1 = attachment1 -- Sets the contraint's attachment1 to attachment1
ballsocketconstraint.Parent = object.Parent -- Sets the contraint's parent to the Motor6D parent
object.Enabled = false -- Disables the Motor6D
char:AddTag("Ragdolled") -- Adds a ragdolled tag
char:WaitForChild("Head").CanCollide = true -- Makes the head collidable
elseif object:IsA("BasePart") then -- Gets all BaseParts
if object.Name == "Handle" then -- If it's a tool handle
continue -- Go to the next iteration
else
object.CanCollide = true -- Makes the object collidable
end
end
end
end
function module.Unragdoll(char)
if not char:FindFirstChild("Humanoid") then
warn("Attempted to unragdoll " .. tostring(char) .. ", which is not a character") -- Warns if is not a character
end
if not char:HasTag("Ragdolled") then
print("Attempted to unragdoll " .. tostring(char) .. " which is already unragdolled...") -- Says if is already unragdolled
end
for i, object in char:GetDescendants() do -- Gets everything in the char
if object:IsA("Motor6D") then -- Gets all Motor6Ds
object.Enabled = true -- Re-enables the Motor6D
char:RemoveTag("Ragdolled") -- Removes the Ragdolled tag
char:WaitForChild("Head").CanCollide = false -- Uncollides the head again
elseif object:IsA("Attachment") then -- Gets all attachments
if object.Name == "RagdollAttachment0" or object.Name == "RagdollAttachment1" then -- Gets all RagdollAttachments
object:Destroy() -- Destroys all RagdollAttachments
end
elseif object:IsA("BallSocketConstraint") then -- Gets all BallSocketConstraints
object:Destroy() -- Destroys all BallSocketConstraints
elseif object:IsA("BasePart") then -- Gets all BaseParts
if object.Name == "Torso" or object.Name == "Head" or object.Name == "Handle" then -- If it's a accessory handle, head, or torso then
continue -- Go to the next iteration of the loop
else
object.CanCollide = false -- Make everything else uncollidable
end
end
end
end
return module
I canβt find anything on the forum, everything is a couple of years old, and I donβt know if they still apply.
Any help making the player collapse?