The Objective - Create a simple ragdoll script that can toggle between ragdoll and normal.
The Problem - The player immediately dies after being ragdolled.
Haven’t really tried any solutions, as I can’t really figure out what’s wrong.
Script 1: PlayerManager (game.ServerScriptService.PlayerManager)
local RagdollHandler = require(script.Parent:WaitForChild("RagdollHandler"))
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local ragdolled = Instance.new("BoolValue")
ragdolled.Name = "Ragdolled"
ragdolled.Parent = character
character:FindFirstChild("Humanoid").BreakJointsOnDeath = false
end)
end)
Script 2: RagdollHandler (game.ServerScriptService.RagdollHandler)
local module = {}
function module.ragdoll(character)
if character.Ragdolled.Value then return end
character.Ragdolled.Value = true
for i, joint in pairs(character:GetDescendants()) do
if joint:IsA("Motor6D") then
local socket = Instance.new("BallSocketConstraint")
local att0 = Instance.new("Attachment")
local att1 = Instance.new("Attachment")
socket.Parent = joint.Parent
att0.Parent = joint.Parent
att1.Parent = joint.Parent
att0.CFrame = joint.C0
att1.CFrame = joint.C1
socket.Attachment0 = att0
socket.Attachment1 = att1
socket.TwistLimitsEnabled = true
socket.LimitsEnabled = true
joint.Enabled = false
end
end
end
function module.unragdoll(character)
if character.Ragdolled.Value then return end
character.Ragdolled.Value = true
for i, joint in pairs(character:GetDescendants()) do
if joint:IsA("Motor6D") then
joint.Enabled = true
elseif joint:IsA("BallSocketConstraint") then
joint.Enabled = false
end
end
end
return module
Script 3: RagdollClient (game.StarterPlayer.StarterCharacterScripts.RagdollClient)
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local ragdolled = character:WaitForChild("Ragdolled", 3)
local function change_state()
if ragdolled.Value then
humanoid:ChangeState(Enum.HumanoidStateType.Physics)
else
humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
end
end
I’d really appreciate if someone can help figure this issue out, I can’t really see any problem from where I’m looking…