I'm making a plugin and i want to make a button insert a model into workspace with the model's ID

I want to achieve a plugin that inserts models (in this case car models) into the workspace.

The issue is that I don’t know how to do it.

I have tried scripting it on my own, searching on DevHub, Doc site, DevForum, YT and google.
Here would be what the plugin would do:

  • Click the button on the toolbar
  • A GUI will open
  • There will be a menu with different cars for you to add to the workspace
  • You click a car and select the design and the selected car gets inserted to the workspace

Pls help me on making this.
Everything woks except for the inserting part

assuming the cars is models, you should check out InsertService’s documentation; another way is to have the cars parented to the plugin’s script, and clone them into the workspace when the button is pressed. not sure if the second choice would work, but it’s worth a try

These kind of tutorials drive me crazy…

I don’t think that would work but I’ll try, could u script the clone script for me pls?

local car1Id = YourCarModelId
MyPluginButton.Click:Connect(function()

	local car1 = game.InsertService:LoadAsset(car1Id)
	car1.Parent = workspace
end)
local car1 = script.MyCar

MyPluginButton.Click:Connect(function()
	car1:Clone()
	car1.Parent = workspace
end)

Try both, didn’t have the chance to do so. by the way, replace “car1Id” with your model’s asset and MyPluginButton with your plugin’s button.

1 Like

Shouldn’t it be MyPluginButton.MouseButton1Click?

Also, should this be in the plugin script or in the button’s localscript?

According to Roblox’s “Intro to Plugins” article in the devhub, no; it should be Click. It should be in a ServerScript.
image

Even if the button is inside a GUI?

In that case, yeah, it should be MouseButton1Click; and it should be a LocalScript. Click should only be used on plugin buttons, not UI ones.

Ok, lets revise:

local car1Id = MyModelId
script.Parent.MouseButton1Click:Connect(function()

	local car1 = game.InsertService:LoadAsset(car1Id)
	car1.Parent = workspace
end)

image

  • Script: The plugin script
  • PoliceCar: One of the car models
  • CarInserterPluginFolder: Where I keep all the plugin assets (the gui isn’t in there yet bc i haven’t finished the ui yet)

Should this be how it looks on the xplorer?
If not, where should I add the models?

Yep, that’s how it should be. You can also use this to get the latest version instead of just the model:

local assetVersionId = game:GetService("InsertService"):GetLatestAssetVersionAsync(model_Id)
game:GetService("InsertService"):LoadAssetVersion(assetVersionId).Parent = game.Workspace