Problem with ragdoll dismemberment

How’s it going? So, I’m trying to work on a ragdoll and it for some reason is breaking with this code, do you guys mind helping? I appreciate it! (It’s supposed to look like roblox’s old 2016 system where arms/legs sometimes fall off the body when they die as a ragdoll btw.)

Here’s the code that is making it break:

local dismemberment = math.random(1,4)

local ll = mode[‘Left Leg’]
local la = mode[‘Left Arm’]
local rl = mode[‘Right leg’]
local ra = mode[‘Right Arm’]

if dismemberment == 1 then
ll.CanCollide = true
ll.LeftArmAttchment:Destroy()
mode.Torso.LeftLeg:Destroy()
mode.Torso.Left2ArmAttchment:Destroy()
end

if dismemberment == 2 then
la.CanCollide = true
la.LeftArmAttchment:Destroy()
mode.Torso.LeftArm:Destroy()
mode.Torso.Left2ArmAttchment:Destroy()
end

if dismemberment == 3 then
rl.CanCollide = true
rl.LeftArmAttchment:Destroy()
mode.Torso.RightLeg:Destroy()
mode.Torso.Left2ArmAttchment:Destroy()
end

if dismemberment == 4 then
ra.CanCollide = true
ra.RightArmAttchment:Destroy()
mode.Torso.RightArm:Destroy()
mode.Torso.Right2ArmAttchment:Destroy()
end

1 Like

You can use 1 if statement with elseifs
example:

if xyz then
dismember zzz
elseif zyz
dismember yyy
end

There are other ways to achieve this in shorter code but this is my bandaid solution