function module.FindInstance(name, class: optional | string, ancestorName: optional | string, Position: Optional | CFrame)
for _, ancestor in game:GetDescendants() do
if ancestor then
if ancestorName then
if ancestor.Name == ancestorName then
for _, item in ancestor:GetDescendants() do
if item.Name == name then
if class then
if item:IsA(class) then
if item:IsA("Model") and item.PrimaryPart.CFrame == Position then
print("Item found with class, CFrame, ancestor & name "..item.Name)
return item
elseif item:IsA("BasePart") and item.PrimaryPart.CFrame == Position then
print("Item found with class, CFrame, ancestor & name "..item.Name)
return item
end
print("Item found with class, ancestor & name "..item.Name)
return item
end
end
#Any idea for improvements??
1 messages · Page 1 of 1 (latest)
if item:IsA("Model") and item.PrimaryPart.CFrame == Position then
print("Item found with CFrame, ancestor & name "..item.Name)
return item
elseif item:IsA("BasePart") and item.PrimaryPart.CFrame == Position then
print("Item found with CFrame, ancestor & name "..item.Name)
return item
end
print("Item found with ancestor & name "..item.Name)
return item
end
end
end
end
end
end
for _, item in game:GetDescendants() do
if item.Name == name then
if class then
if item:IsA(class) then
if item:IsA("Model") and item.PrimaryPart.CFrame == Position then
print("Item found with class, CFrame & name "..item.Name)
return item
elseif item:IsA("BasePart") and item.PrimaryPart.CFrame == Position then
print("Item found with class, CFrame & name "..item.Name)
return item
end
print("Item found with class & name "..item.Name)
return item
end
end
if item:IsA("Model") and item.PrimaryPart.CFrame == Position then
print("Item found with CFrame & name "..item.Name)
return item
elseif item:IsA("BasePart") and item.PrimaryPart.CFrame == Position then
print("Item found with CFrame & name "..item.Name)
return item
end
print("Item found with name "..item.Name)
return item
end
end
end
What do you need this for?
to check if item exists in both server and client; as well as for other stuff
i think you could remove a lot of the nesting by doing "if _ and _ then"
cause its pretty hard to follow with all of the nesting
its just a choice though honestly
Couldn't you just (from the client) parse the part name as an argument and maybe it's parent into a remote function to check if it exists? E.G
local function isClientInstance(instanceName, parent)
return (parent:FindFirstChild(instanceName) == nil)
end
OR (im unaware if this version would work or not)
just parse the part and see if the server recieves it? E.G:
local function isClientInstance(instance)
return (instance == nil)
end
that could work
yea, it works
if the point is checking if it only exists on the client or server then that would work
it returns nil if the item only exists in client whenever you pass the instance[which only exists in client] to server
?