#Any idea for improvements??

1 messages · Page 1 of 1 (latest)

plush egret
#
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
                            
#
                            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
solar grove
#

What do you need this for?

plush egret
#

to check if item exists in both server and client; as well as for other stuff

wicked creek
#

cause its pretty hard to follow with all of the nesting

#

its just a choice though honestly

orchid pelican
# plush egret to check if item exists in both server and client; as well as for other stuff

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
solar grove
#

that could work

plush egret
#

yea, it works

solar grove
#

if the point is checking if it only exists on the client or server then that would work

plush egret
#

it returns nil if the item only exists in client whenever you pass the instance[which only exists in client] to server

solar grove
#

?