Deleting the RootPart results in the camera going unconventional ways (which definitely just means I shouldn’t have deleted it), and somehow I can still move the character. (And for ‘I don’t know’ reasons.)
Here’s my script by the way, it’s nothing special. It might look spaghetti-like because I’m using strict coding.
--!native
--!optimize 2
--!strict
local Character: Model = script.Parent
local Player: Player = game.Players:GetPlayerFromCharacter(Character)
local Humanoid: Humanoid? = Character:FindFirstChildOfClass('Humanoid')
local RootPart: BasePart? = nil
local RagdollVal: BoolValue = Instance.new('BoolValue')
RagdollVal.Name = 'Ragdoll'
RagdollVal.Parent = Character
RagdollVal.Changed:Connect(function(value: boolean)
if Humanoid then
RootPart = Humanoid.RootPart
if RootPart then
RootPart.CanCollide = not value -- false if ragdoll
for _, v in Character:GetDescendants() do
if v:IsA('BasePart') and v.Name == 'Head' then
v.CanCollide = value -- true if ragdoll
end
if v:IsA('Motor6D') then
if value then
local Att0: Attachment, Att1: Attachment = Instance.new('Attachment'), Instance.new('Attachment')
Att0.CFrame = v.C0
Att1.CFrame = v.C1
Att0.Parent = v.Part0
Att1.Parent = v.Part1
local BSC: BallSocketConstraint = Instance.new('BallSocketConstraint')
BSC.Attachment0 = Att0
BSC.Attachment1 = Att1
BSC.Parent = v.Part0
if v.Part1 and v.Part1.Name == 'Head' then
BSC.LimitsEnabled = true
BSC.TwistLimitsEnabled = true
end
else
local Att0: Attachment?, Att1: Attachment? = nil, nil
local BSC: BallSocketConstraint? = nil
if v.Part0 then
Att0 = v.Part0:FindFirstChildWhichIsA('Attachment')
BSC = v.Part0:FindFirstChildWhichIsA('BallSocketConstraint')
end
if v.Part1 then
Att1 = v.Part1:FindFirstChildWhichIsA('Attachment')
end
if Att0 then
Att0:Destroy()
end
if Att1 then
Att1:Destroy()
end
if BSC then
BSC:Destroy()
end
end
v.Enabled = not value -- false if ragdoll
end
if v:IsA('Weld') and v.Name == 'AccessoryWeld' then
if value then
local WC: WeldConstraint = Instance.new('WeldConstraint')
WC.Part0 = v.Part0
WC.Part1 = v.Part1
WC.Parent = v.Parent
else
local WC: WeldConstraint? = nil
if v.Parent then
WC = v.Parent:FindFirstChildWhichIsA('WeldConstraint')
end
if WC then
WC:Destroy()
end
end
v.Enabled = not value -- false if ragdoll
end
end
end
end
end)
Also, I would like to mention that any tips to improving my spaghetti code is appreciated, but you don’t have to, of course.
