I mean, I can easily loop through the torso to find Motor6Ds and make a bunch of ifs and elseifs to find a specific body part,
but for example, when you have a huge table with a lot of strings in it, you wouldn’t probably type a lot of if statements?
I want to make it so that in the code, when the part is touched, it checks the body part of a character and removes its motor6D in a torso, the code is unfinished:
local motorsToRemove = {"Left Hip", "Right Hip", "Left Shoulder", "Right Shoulder", "Neck"}
-- for example, "Neck" == "Head", "Left Hip" == "Left Leg" and etc..
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("HumanoidRootPart") then
for _, motor in pairs(hit.Parent.Torso:GetChildren()) do
-- if there is a body part attributed to a motor, it checks the same body part if it has the motor, and then it is destroyed
end
end
end)
I don’t know what you are trying to do specifically due to your wording, but you can just use IsA() to check if it the part is a Motor6D.
local motorsToRemove = {"Left Hip", "Right Hip", "Left Shoulder", "Right Shoulder", "Neck"}
-- for example, "Neck" == "Head", "Left Hip" == "Left Leg" and etc..
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("HumanoidRootPart") then
for _, motor in pairs(hit.Parent.Torso:GetChildren()) do
if motor:IsA("Motor6D") then
motor:Destroy()
end
end
end
end)
So basically, motor6Ds that connect all body parts, are stored in the character’s torso, and here’s what I am trying to do:
The script checks which body part the touched part just hit, and then, the motor that connects the touched body part to a torso, gets removed.
So that’s why I put like “Neck” == “Head”, It is to basically associate touched body parts to their motor, and the same associated motor gets removed
Still thanks for your reply and much appreciate it!
You can link certain parts to a table in order to index them
local motorsToRemove = {
[“Head”] = “Neck”
}
For example, it could look like this:
local motorsToRemove = {
[“Head”] = “Neck”
} -- you can add the other body parts
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("HumanoidRootPart") then
local found = motorsToRemove[hit.Name]
if not found then return end -- if there is no motor to remove there is no point in running the search
for _, motor in pairs(hit.Parent.Torso:GetChildren()) do
if motor:IsA("Motor6D") then
if motor.Name == found then
motor:Destroy()
end
end
end
end
end)
``