I have a ragdoll script for my game that toggles a BoolValue when it should ragdoll. Currently, the player is still able to control their character while they are ragdolling. How could I fix this?
Example video:
Code:
local humanoid = script.Parent:WaitForChild("Humanoid")
humanoid.BreakJointsOnDeath = false
local character = script.Parent
local torso = character:WaitForChild("Torso")
local hrp = character:WaitForChild("Torso")
local animatescript = character:WaitForChild("Animate")
local RagdollStorage = Instance.new("Folder")
RagdollStorage.Parent = humanoid.Parent
RagdollStorage.Name = (humanoid.Parent.Name .. "Ragdoll")
--------------------------------------------------
script.Ragdolling.Changed:Connect(function(newvalue)
if script.Ragdolling.Value == true then
print("Starting " .. character.Name .. "'s ragdoll")
animatescript.Disabled = true
script.Parent.Dash.SlideDisabled.Value = true
for index,joint in pairs(script.Parent:GetDescendants()) do
if joint:IsA("Motor6D") then
local socket = Instance.new("BallSocketConstraint")
local a1 = Instance.new("Attachment")
local a2 = Instance.new("Attachment")
a1.Parent = joint.Part0
a2.Parent = joint.Part1
socket.Parent = joint.Parent
socket.Attachment0 = a1
socket.Attachment1 = a2
a1.CFrame = joint.C0
a2.CFrame = joint.C1
socket.LimitsEnabled = true
socket.TwistLimitsEnabled = true
joint.Enabled = false
joint.Parent = RagdollStorage
end
end
elseif script.Ragdolling.Value == false then
animatescript.Disabled = false
script.Parent.Dash.SlideDisabled.Value = false
print("Stopping " .. character.Name .. "'s ragdoll")
for index,joint in pairs(script.Parent:GetDescendants()) do
if joint:IsA("BallSocketConstraint") then
joint:Destroy()
end
end
for i, m6d in pairs(RagdollStorage:GetDescendants()) do
if m6d:IsA("Motor6D") then
if m6d.Name == 'RootJoint' then
m6d.Parent = hrp
m6d.Enabled = true
else
m6d.Parent = humanoid.Parent.Torso
m6d.Enabled = true
end
end
end
end
end)
--------------------------------------------------
humanoid.Changed:Connect(function(whatchanged)
if whatchanged == 'Health' then
if humanoid.Health < 10 then
script.Ragdolling.Value = true
else
script.Ragdolling.Value = false
end
end
end)
Any help would be much appreciated!