All, I have run into a bit of a roadblock and any help would be appreciated. Maybe down the road this will help others also.
I am attempting to insert models into a running game via a ServerScript. As far as I can tell, and my knowledge to the subject is very small, my script reads as it should. However, this difficult to understand error keeps returning.
The following is the block of code I am attempting to use to insert the model:
local InsertService = game:GetService("InsertService")
local modelID = 1234567890 --Obviously a real model ID is here
local model = game:GetObjects("rbxassetid://"..modelID)[1] --The error throws on this line
local asset = InsertService:LoadAssetVersion(model)
asset:SetPrimaryPartCFrame(script.Parent.CFrame)
asset.Parent = game.Workspace
The error seemingly throws when I attempt to call the GetObjects() function.
I am attempting to use this model inserting technique to replace a conventional method of spawning vehicles/assets out of ServerStorage because some of the vehicles being spawned are rather large in file size, and having a multitude of these sitting in ServerStorage makes the place difficult to get loaded in Studio. So, having each item as a model in my inventory (yes, the models and places are all on my profile) keeps them out of the place’s memory completely until one is needed.
A little added context to help you understand the code:
The script holding this code is inside of a Part, which is also the click detector (being done through an event). The model being inserted has a Primary Part. The Primary Part’s orientation and location must match the click detector’s orientation and location in order for the model to insert/spawn in the correct position. The Primary Part and the click detector part are actually identical instances, except the model’s Primary Part doesn’t have the scripting in it (obviously). This is why I am calling the SetPrimaryPartCFrame() function before parenting the model to Workspace.
I’ll also mention the models being inserted have scripts in them, however that is irrelevant at this very moment. Though, I thought it was worth mentioning in case your solutions differ due to the fact.
Thanks in advance.