Inserting Models via a Script Fails & Returns Error The current thread cannot call 'GetObjects' (lacking capability Plugin)

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.

4 Likes

i think getobjects only works in studio

2 Likes

I attempted testing in a legitimate game server as well as in Studio play-test mode, neither was successful. Is there a different method I should be using to accomplish this in a running server?

1 Like

What this actually means is that the current thread has an insufficient security context level. GetObjects has the plugin security tag meaning it can only be used by plugins or the command bar. Even in Studio, you can’t use this method outside of those two.

Although it hasn’t been reached, LoadAssetVersion would also be an error because it expects a number as its argument not an instance. GetObjects returns an array of instances.

If you want to insert a model for runtime purposes, you should be using InsertService:LoadAsset.

3 Likes

Thank you so much! This was the little tidbit I was needing. It is functioning flawlessly now.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.