local lowertorso = char:FindFirstChild("LowerTorso")
local uppertorso =char:FindFirstChild("UpperTorso")
local head = char:FindFirstChild("Head")
local leftupperarm = char:FindFirstChild("LeftUpperArm")
local leftlowerarm = char:FindFirstChild("LeftLowerArm")
local lefthand = char:FindFirstChild("LeftHand")
local leftfoot = char:FindFirstChild("LeftFoot")
local leftupperleg = char:FindFirstChild("LeftUpperLeg")
local leftlowerleg = char:FindFirstChild("LeftLowerLeg")
local rightupperarm = char:FindFirstChild("RightUpperArm")
local rightlowerarm = char:FindFirstChild("RightLowerArm")
local righthand = char:FindFirstChild("RightHand")
local rightfoot = char:FindFirstChild("RightFoot")
local rightupperleg = char:FindFirstChild("RightUpperLeg")
local rightlowerleg = char:FindFirstChild("RightLowerLeg")
how do i check all of these variables without creating a long line of And statements?
if lefthand and right hand and..... so on and on then
---
end
I think itâd be the best to only get the variable you need most I believed.
May I ask what you are trying to do with these variables? Sorry, I just wanna know why youâd these variables maybe I might be able to provide a solution.
yeah, if i die by falling on the void it will throw an error saying its trying to index ânilâ on character because the character is already gone and i dont want that
Maybe just a single Character:FindFirstChild(âHumanoidRootPartâ) line? unless you want an extreme way of checking if all of the parts exist.
function CheckForParts(Character)
local Limbs = {
"LowerTorso", "UpperTorso", "Head",
"LeftUpperArm", "LeftLowerArm", "LeftHand",
"LeftFoot", "LeftUpperLeg", "LeftLowerLeg",
"RightUpperArm", "RightLowerArm", "RightHand",
"RightFoot", "RightUpperLeg", "RightLowerLeg"
}
for _,CheckPart in pairs(Character:GetChildren()) do
if table.find(Limbs, CheckPart.Name) then
table.remove(Limbs, table.find(Limbs, CheckPart.Name))
end
end
if #Limbs == 0 then
-- All parts exist
end
end
Which is kinda unnecessary. In my opinion Iâd just put a single line that detects if HumanoidRootPart existed once the Died function has been called.
if humanoid dies and then i just need to check for humanoid root part then it means i dont have to FindFirstChild on all of the limbs?
humanoid.Died:Connect(function()
local rig = humanoid.RigType
if rig == rigtype.R15 then
if char:FindFirstChild("HumanoidRootPart") then -- ur saying only this is necesary?
local lowertorso = char.LowerTorso
local uppertorso =char.UpperTorso
local head = char.Head
-- and then the rest of the bodyparts
Hereâs the code that checks if HumanoidRootPart exist upon a death. Itâll always print âNOTâ if the rootpart doesnât exist basically if you jump into the void.
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
wait()
Character.Humanoid.Died:Connect(function()
if Character:FindFirstChild("HumanoidRootPart") then
print("EXISTED")
else
print("NOT")
end
end)
end)
end)
Not sure if this works. But if it does, it should be a good way to create the constraints without writing the creation code separately for each bodypart.
Edit: Iâve done some edits to this. For example, I had the skipIteration declaration and check in wrong places.
local attachs = {}
for _, v in ipairs(char:GetDescendants()) do
if v.Name:match("RigAttachment") then
attachs[#attachs+1] = v
end
local attachsNum = #attachs
-- this variable is used to make sure that
-- attachments that have been used
-- are checked no more times
local skipIteration = false
for i = attachsNum, 1, -1 do
if skipIteration then
skipIteration = false
continue
end
local attach = attachs[i]
local loop2Start = i-1
for i2 = loop2Start, 1, -1 do
local attach2 = attachs[i2]
if attach2.Name == attach.Name then
skipIteration = true
if i2 ~= loop2Start then
-- related to the same thing as skipIteration
-- replaces the found attachment in the table with another attachment
-- the other attachment is skipped on its original index
-- using skipIteration
attachs[i2] = attachs[loop2Start]
end
-- create a ball socket constraint using attach and attach2
break
end
end
end
string.match looks for the other string inside the the first string. v.Name:match("RigAttachment") works the same as string.match(v.Name, "RigAttachment")
It checks if "RigAttachment" is found in the name of the instance. So the condition will be met if the name is "RightShoulderRigAttachment" or "RootRigAttachment", for example.