PcoWSkbVqDnWTu_dm2ix
Collapse Sidebar

GetObjects

This function returns an array of Instance|Instances associated with the given Articles/Content|content URL.

This function can be used to insert content from the Roblox library, such as:

  • Models
  • Decals
  • Meshes
  • Plugins
  • Animations

It is not possible to insert Sound|Sounds using this method as they do not have an Instance associated with them (rather just a Articles/Content|content URL).

Unlike InsertService/LoadAsset, GetObjects does not require an asset to be ‘trusted’. This means that an asset does not need to be owned by the logged in user, or created by Roblox, to be inserted. However, if the asset is not owned by the logged in user it must be freely available.

Due to this function’s security context it can only be used by plugins or the command bar. For an alternative that can be used in Script|Scripts and LocalScript|LocalScripts, see InsertService/LoadAsset.

Parameters

Name Type Default Description

url

The given Articles/Content|content URL

Returns

Return Type Summary

An array of Instance|Instances associated with the Articles/Content|content URL


Code Samples


View a plugin’s source code

If you want to view a plugin’s source code without installing it, you can use DataModel/GetObjects to download the plugin. The code sample below includes a function that will take a plugin’s website URL and insert the plugin into the currently selected Instance or the Workspace.

Due to DataModel/GetObjects|GetObjects’ security context, this function can only be used in the command line or in a plugin.

local Selection = game:GetService("Selection")

local function downloadPlugin(webURL)
    -- get the content URL
    local contentID = string.match(webURL, "%d+")
    local contentURL = "rbxassetid://"..contentID

    -- download the objects
    local objects = game:GetObjects(contentURL)

    -- decide where to parent them
    local selection = Selection:Get()
    local parent = #selection == 1 and selection[1] or workspace

    -- parent the objects
    for _, object in pairs(objects) do
        object.Parent = parent
    end
end

Batch convert decal IDs

The content ID of a Decal on the Roblox website is associated with a Decal Instance rather than the actual Articles/Content|content ID of the texture.

The code below, will use DataModel/GetObjects to insert Decal objects into place and read their Decal/Texture property to obtain the image Articles/Content|content IDs.

To use this code sample, enter the web URLs of the decals you’d like to convert into the array named IMAGES (as strings). A dictionary with the converted textures will be outputted.

local IMAGES = {
	-- Insert Decal web URLs in an array here (as strings)
}

-- open the dictionary
local outputString = "textures = {"

-- utility function to add a new entry to the dictionary (as a string)
local function addEntryToDictionary(original, new)
	outputString = outputString
		.."\n"  -- new line
		.."    "  -- indent
		.."[\""..original.."\"]" -- key
		.." = \""..new.."\"," -- value
end

print("Starting conversion")

for _, webURL in pairs(IMAGES) do

	-- get the content URL
	local contentID = string.match(webURL, "%d+")
	local contentURL = "rbxassetid://"..contentID

	local success, result = pcall(function()
		local objects = game:GetObjects(contentURL)
		return objects[1].Texture
	end)

	if success then
		addEntryToDictionary(webURL, result)
	else
		addEntryToDictionary(webURL, "Error downloading decal")
	end

	-- wait to avoid freezing Roblox
	wait()
end

print("Conversion complete")

-- close the dictionary
outputString = outputString.."\n}"

-- print the dictionary
print(outputString)