Hi, I’ve had a problem with exploiters moving their character while ragdolled, and I don’t want them to move. I have tried using network ownership but it didn’t work.
How can I make it so the character cannot move, I would preferably want to do this WITHOUT anchoring the player. Here’s the script I have now.
local Players = game:GetService("Players")
local CollectionService = game:GetService("CollectionService")
local character = script.Parent
local LocalPlayer = Players:GetPlayerFromCharacter(character)
local humanoid = character:WaitForChild("Humanoid")
local Dead = false
humanoid.BreakJointsOnDeath = false
Players.CharacterAutoLoads = false
local old_joints = {}
local joint_data = {}
-- Cache joint information
for _, joint in ipairs(character:GetDescendants()) do
if joint:IsA("Motor6D") then
table.insert(old_joints, joint:Clone())
joint_data[joint] = {
Part0 = joint.Part0,
Part1 = joint.Part1,
C0 = joint.C0,
C1 = joint.C1
}
end
end
local function Ragdoll()
for joint, data in pairs(joint_data) do
if joint:IsA("Motor6D") and joint:IsDescendantOf(character) then
local socket = Instance.new("BallSocketConstraint")
local a1 = Instance.new("Attachment")
local a2 = Instance.new("Attachment")
CollectionService:AddTag(socket, "Ragdoll")
CollectionService:AddTag(a1, "Ragdoll")
CollectionService:AddTag(a2, "Ragdoll")
a1.Parent = data.Part0
a2.Parent = data.Part1
socket.Parent = joint.Parent
socket.Attachment0 = a1
socket.Attachment1 = a2
a1.CFrame = data.C0
a2.CFrame = data.C1
socket.LimitsEnabled = true
socket.TwistLimitsEnabled = true
joint:Destroy()
end
end
end
local function Unragdoll()
for _, inst in ipairs(CollectionService:GetTagged("Ragdoll")) do
inst:Destroy()
end
for _,part:BasePart in character:GetDescendants() do
if part.ClassName == "BasePart" or part.ClassName == "Part" then
part:SetNetworkOwner(LocalPlayer)
end
end
for _, joint in ipairs(old_joints) do
local newJoint = joint:Clone()
newJoint.Parent = character
newJoint.Part0 = character:FindFirstChild(joint.Part0.Name)
newJoint.Part1 = character:FindFirstChild(joint.Part1.Name)
if newJoint.Part0 and newJoint.Part1 then
newJoint.Parent = newJoint.Part0
else
warn("Failed to restore joint: " .. joint.Name)
newJoint:Destroy()
end
end
end
local function onHealthChanged()
if humanoid.Health < 10 and Dead == false then
Dead = true
Ragdoll()
end
end
humanoid.HealthChanged:Connect(onHealthChanged)
humanoid.Died:Connect(function()
if not Dead then
Dead = true
Ragdoll()
end
end)
-- Add a function to toggle ragdoll state
local function ToggleRagdoll()
if Dead then
Unragdoll()
Dead = false
else
Ragdoll()
Dead = true
end
end