This script is a landmine script. It requires my r15 ragdoll script. The landmine would launch players' bodies up in the air and blow off limbs by chance. The script would select any random children in the player's character ten times and checks if it's the right limb (e.g. RightUpperArm). The script works fine. However, if it tries to remove a limb's joint that's already been removed, it would error: RagdollRightUpperArm is not a valid member of Model
I tried to fix my problem on line 24. But it doesn't work.
touch = true
function onTouch(PART)
if touch then
touch = false
if touch == true then return end
local humanoid = PART.Parent:FindFirstChild("Humanoid")
if humanoid ~= nil then
math.randomseed(tick())
local sound = script.Parent:WaitForChild("Boom")
sound:Play()
humanoid.Health = 0
PART.Velocity = Vector3.new(math.random(1,10), 500, math.random(1,10))
PART.RotVelocity = Vector3.new(math.random(10,25), 0, math.random(10,25))
local function chance(percentage)
return math.random() < percentage / 100
end
if chance(60) then
for i = 1, 10 do
local children = humanoid.Parent:GetChildren()
wait(0.001)
local removeJoint = (children[math.random(1,#children)])
if removeJoint.Name == "RightUpperLeg" or removeJoint.Name == "RagdollRightUpperLeg" then
if humanoid.Parent.RagdollRightUpperLeg == nil then
print("Right leg already blown off!")
end
humanoid.Parent.RagdollRightUpperLeg:Destroy()
print("Right leg blown off!")
end
if removeJoint.Name == "RightUpperArm" or removeJoint.Name == "RagdollRightUpperArm" then
if humanoid.Parent.RagdollConstraintRightUpperArm == nil then
print("Right arm already blown off!")
end
humanoid.Parent.RagdollRightUpperArm:Destroy()
print("Right arm blown off!")
end
if removeJoint.Name == "LeftUpperLeg" or removeJoint.Name == "RagdollLeftUpperLeg" then
if humanoid.Parent.RagdollLeftUpperLeg == nil then
print("Left leg already blown off!")
end
humanoid.Parent.RagdollLeftUpperLeg:Destroy()
print("Left leg blown off!")
end
if removeJoint.Name == "LeftUpperArm" or removeJoint.Name == "RagdollLeftUpperArm" then
if humanoid.Parent.RagdollLeftUpperArm == nil then
print("Left arm already blown off!")
end
humanoid.Parent.RagdollLeftUpperArm:Destroy()
print("Left arm blown off!")
end
end
else
print("No limbs blown off.")
end
end
wait(1)
touch = true
end
end
script.Parent.Touched:connect(onTouch)

1 comment
Yes, it does work. Thanks! :)