What would be the most efficient way to get a model from server storage using a custom ID system? I was thinking about renaming all models to their ID’s then looping through the decedents / children (Depending on how I layout the folders) looking for a match based on their names, however I’m not sure if it will scale well.
-- Something along the lines of this
for _, item in ipairs(ServerStorage:GetChildren()) do
if item.Name == customID then
print("found item")
break
end
end
Hello.
Assuming the descendants never have something added or removed to it, you can do an initial loop to cache all instances based on their name using a dictionary. You can then use a module script with a function to get models from this cache
if ServerStorage:FindFirstChild(customID) then
print("found item")
end
or am i missing something? Could you be more specific with what you are trying to do? If you just want to organise items using ID names I think the code above is the most efficient way.
Probably a helper dictionary that has the customID as a key and the instance as a value. Then all you have to do to fetch it is items[customID] where items is the helper dictionary.
However if you insist to use instances under ServerStorage directly, you can still fetch the item without looping over, with the FindFirstChild function:
local item = ServerStorage:FindFirstChild(customID)
if item then
print("Item found:", item)
else
print("No item found with given custom ID")
end
In general if you’re trying to scale up a problem, you should be thinking what you’re trying to optimize for. Server memory? Fetch speed? etc. Depending on your optimization goal the solution may change. There isn’t a one size fits all solution for most things.
My main concern is fetch speed. I do have a dictionary set in place for info on the models (A module script in Replicated storage) however I wasn’t sure if there was going to be an issue on the client as the models are stored in server storage that path wouldn’t exist on the client and give an error. To be clear, I don’t need the client to be able to access the models themselves only the associated info in the dictionary, its the server that will be handling models.
Sorry for not explain clearly, Would naming the model a custom ID then using a method like you have shown above be the fastest and most efficient way to get the model within a list of hundreds or would there be a way to cache the model and use that?
Wouldn’t this just be getting the reference for the actual model? Correct me if I’m wrong, but if my thinking is correct, this wouldn’t have minimal effect on loading times, since the real bulk of loading time comes from cloning it into e.g. workspace, rather than actually locating the model and creating a new reference.