Hello everyone,
In my code, I would like to check if the parent doesn't an attachment. Since there is a :IsA
, I tried to do the opposite. Here is what I can do in javascript:
Javascript:
if !(part.Name == "lkjhgd;") {
//random code....
}
Lua:
for _, v in ipairs(part:GetChildren()) do if v:IsA("Attachment") then end end
So, is there a way I can do that in lua? Thanks for the help!
Okay so from my understanding you're trying to check if the part doesn't have a child thats an attachment. In this case its pretty simple to make a check and the rest is up to you.
local function hasAttachment(part) for _, v in pairs(part:GetChildren()) do if v:IsA("Attachment") then return true end return false end end if hasAttachment(part) then print("The part has an attachment!") else print("The part doesn't have an attachment!") end
Sorry if I misinterpreted what you said, reply to my answer if so, otherwise tag me as answered if this solved your issue.
This answer is similar to Bandit's one but there is simpler way to achieve what he has done: FindFirstChildWhichIsA
or FindFirstChildOfClass
(use the first).
local Attachment = Parent:FindFirstChildWhichIsA('Attachment'); if(Attachment)then; else end;
But if you wan't to revert is as you said, !==
in JavaScript
if i remember correctly, there is keyword not
which reverts all given values:
not true -- false not false -- true --/In your case: local Attachment = Parent:FindFirstChildWhichIsA('Attachment'); if(not Attachment)then print('no attachment'); end
I tried to use code format like in java script so maybe it will look better for you