Inserting a Plane/vehicle into the game via a GUI

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I want to be able to press a button on a GUI and then it inserts that vehicle into the game.

  2. What is the issue? The issues is that it doesn’t insert when you press the button.
    Screen capture - 3710a8ddf12f001a9236458e2cdf81c3 - Gyazo

  3. What solutions have you tried so far? I have tried both these 2 pieces of code;

ID = script.Parent.B737ID.Value
Object = game:GetService("InsertService"):LoadAsset(ID)
Object.Parent = game.Workspace

You put a ID in a NumberValue
and

script.Parent.MouseButton1Click:connect(function()
	InsertService:LoadAsset("--Put ID here--")
end)

If anyone has any suggestions on how to do this please let me know! :slight_smile:

Maybe you should set the position of the object after parenting it to workspace?

Object.Position = Vector3.new(0, 0, 0)

Also, you should load assets on the server rather than the client as the player can only see it and nobody else.

Make sure that the ID you got is actually the same on the roblox website.

I want it to spawn ontop of the player otherwise if I set a place, it has the potential to get stuck in the airport or in the taxiways.

You can make the position of the object 10 studs above the character’s head then.

You need to load the asset from the server side by using a remote event

-- server side
local RepStorage = GetService("ReplicatedStorage")
local Event = RepStorage:WaitForChild("LoadAsset") or Istance.New("RemoteEvent", RepStorage) 
Event.Name = "LoadAsset"

Event.OnServerEvent:Connect(function(player, id)
    Object = game:GetService("InsertService"):LoadAsset(id)
    Object:MoveTo(Vector3.new(0, 0, 0)) --try this
    Object.Parent = workspace
end)

-- local side
local Event = game:GetService("ReplicatedStorage"):WaitForChild("LoadAsset")

script.Parent.MouseButton1Click:connect(function()
    local text = script.Parent.TextBox.Text
    if tonumeber(text) then
	    Event:FireServer(tonumeber(text))
    end
end)
1 Like

Ok, I will add the remote event and try that!

1 Like

Just one thing, if you are using Object:MoveTo() then make sure that the Object (model) has a primary part.

2 Likes

Sorry, I am a bit new to scripting so I put the serverside in ServerScriptService and the LocalSide in the GUI, is that correct?

yes, in the server side use a Script, in the local side use a LocalScript

1 Like

Where does the vehicle ID go? :slight_smile:

you need to add a textbox to your gui and send the text with the remote event to the server

1 Like

Screen capture - 1893d5796ff4e61273fe50ec01e9950a - Gyazo I am not sure why it isn’t working.

oh, if you have something like that then you can set the button text as the name of the vehicle and then put a dictionary in the script, like that:

local vehicles = {
    ["Vehicle name 1"] = ID; --set the names and the ids
    ["Vehicle name 2"] = ID;
    ["Vehicle name 3"] = ID;
}

-- the button:
script.Parent.MouseButton1Click:connect(function()
	Event:FireServer(vehicles[script.Parent.Text])
end)

or something similar

Ok, I will try that thanks! :slight_smile:

1 Like

Is this client or server side?

You don’t need to load the asset in the game, you can just leave the model in ServerStorage and clone it to workspace when you want to load it

this is client side, the model loader is server side, you could also do as @Jxl_s says if you want

Would this cause extra lag due to the airline growing, we will buy more planes and other vehicles which would cause a lot of lag I think?

It shouldn’t cause any lag, in fact the response times are much shorter if you do as she says, becouse the game dont need to load the asset but just copy it from the server storage and paste it to the workspace

1 Like

Have you got any good Youtube videos that I could watch that shows how you would do this?