Loading a model into the game with a script

Hello,

I want to do something where you can access a model from the roblox library through a script and load it into the game when a certain command is passed.

What I am trying to do is:
Access and load a model into my game through a script.
The model is private and will only load to certain people.

Is it possible to do something like this and if it is, could I get some help on the coding part?

2 Likes

You can use InsertService | Roblox Creator Documentation but it must be created or owned by either the game creator or Roblox.

1 Like

Is there a way I can give access only to a few people? So not everybody can download the model, only a few people who I want to share it with.

2 Likes

If You Want Load To Game Model With Id Use This

--// Script Locals
local InsertService = game:GetService("InsertService")
local Id = 12345 --// Put Here Your Model Id
local Model = InsertService:LoadAsset(Id)
--// Main Script
Model.Parent = game.Workspace
2 Likes

Are you referring to the command to load the model in the game?

1 Like

Yes. I want the command to load the model into the game for only a few people. Their User IDs would be listed in the same script. So it loads only if they are the game creator. If there is a different game creator, the model would not load into studio. I do not know how to load the model when it is private because if I make it public, everybody would get access to it which I don’t want.

Well then you can do something like this:

local Players = game:GetService("Players")
local InsertService = game:GetService("InsertService")
local AdminsTable = {}

Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message)
		if message:sub(1,7) == ":insert" and table.find(AdminsTable, player.UserId) then
			local assetId = tonumber(message:sub(9))
			local success, model = pcall(InsertService.LoadAsset, InsertService, assetId)
			if success and model then
				model.Parent = workspace
			else
				warn("There was an error loading the model.")
			end
		end
	end)
end)

If the model is private, it will still load if the model is created or owned by the game creator or Roblox.

3 Likes

Thanks, its great! But, I wanted it in the command bar. They enter key in the commander bar and then the model loads, not the chat.

You mean a command bar UI that you created? If so, you can use a remote event.

1 Like

They enter the key given to them here and if the person is in the list, the model loads in. It’s the command bar built into roblox studio.

I don’t think there is a way to do that in the built-in command bar in roblox studio.

1 Like

Is there a way to do that with a plugin I created?

It could be possible, but I think there is no way to check if the person is on the list. Also, what do you need this for?

1 Like

I need this for making a product whitelist. I thought for a while and decided that I wanted to try to make a product whitelist. Making something where a person types in a code, and if the person is whitelisted, the model is loaded into studio. And then they can use it.