Problems with insert model script

Im trying to make a script which inserts a model with an ID from a textbox when you press a button. I dont know why it does not work.
Script:

local ID = tonumber(script.Parent.Parent.TextBox.Text)
local InsertService = game:GetService("InsertService")
local char = game.Players.LocalPlayer.Character 


script.Parent.MouseButton1Click:Connect(function(hi)
	local Model = InsertService:LoadAsset(ID) 
	local NewModel = Model:GetChildren()[1] 
	 
	NewModel.Parent = workspace 
	NewModel:MoveTo(char.HumanoidRootPart.Position + 0,0,15)
	Model:Destroy() 
end)


Error:
image
Line with the error:

	local Model = InsertService:LoadAsset(ID) 
2 Likes

Can you please tell which line is the error from?

2 Likes

the one with :LoadAsset() 30characters

1 Like

This error usually means that there is nothing on the argument you’ve provided in the script. In other words, ID has nothing it, so it tried to load that one, but it couldn’t.

Are you sure there is something on the TextBox?

2 Likes

Can you try changing this line

local Model = InsertService:LoadAsset(ID) 

To this

local Model = InsertService:LoadAsset(tonumber(script.Parent.Parent.TextBox.Text)) 

Also, is this a LocalScript or a normal Script?

2 Likes

local script 30 characterssssss

1 Like

Ok i understandimage

1 Like

But how would I do it from a UI if I cannot insert it from the client?

1 Like

Use Remote Event. It could be abused, so make sure you debounce it correctly.

2 Likes

Now I have no idea how to fix this.
Script:

local InsertService = game:GetService("InsertService")
local folder = script.Parent
local ID = folder.ID
local event = folder.ClickID


event.OnServerEvent:Connect(function(hi)
	local char = hi.Character
	local Model = InsertService:LoadAsset(tonumber(ID.Value))  
	local NewModel = Model:GetChildren()[1] 
		 
	NewModel.Parent = workspace 
	NewModel:MoveTo(char.HumanoidRootPart.Position + 0,0,15)
	Model:Destroy()
end)

Error:
image Line 9
@changeno

2 Likes

InsertService::LoadAsset can error if: it doesn’t exist (404), it failed to get it or the game creator doesn’t own the asset. pcall should be used to handle these errors.

Anywho, is the ID changed on the server or client? The Value doesn’t replicate to the server if changed on the client.

1 Like

Yeah, I noticed that, but how would I give a value the text of a UI in the server instead of the client?

Pass it as an argument in FireServer and receive it as a parameter in the OnServerEvent, remember that the first parameter is always the Player.

1 Like

You can only insert models created by the owner of the game you want to insert said model into.
The same goes for groups.

I’m sorry if someone mentioned this already. I didn’t get to read all the replies.

1 Like

Is there any way of inserting other models that the group doesnt own?

No.

I’m judging that this is done to allow developers to keep their source hidden, and use a Require() function on their models.

1 Like

It would be cool that there was a feature in configure model where you cant set if other players can insert it or not.

image

image

image

image

Did what you told me, I dont think its correct since that happens.

Localscript(textbox):

local textbox = script.Parent.Parent.TextBox
local event = workspace.InsertModel.ClickID
local value = workspace.InsertModel.ID

script.Parent.MouseButton1Click:Connect(function(hi)
	if textbox.Text ~= "ID" or textbox.Text ~= nil then
		value.Value = textbox.Text
		event:FireServer(tonumber(textbox.Text))
	end
end)


Serverscript(in a folder in workspace):

local InsertService = game:GetService("InsertService")
local folder = script.Parent
local ID = folder.ID
local event = folder.ClickID


event.OnServerEvent:Connect(function(hi, text)
	local char = hi.Character
	local Model = InsertService:LoadAsset(text)  
	print("Value:" ..ID.Value)
		 
	Model.Parent = workspace 
	Model:MoveTo(Vector3.new(char.HumanoidRootPart.Position))
end)


The main thing is if you own the mocel.

The problem is that the value’s value only changes in the client, how do I change it in the server?

I have tried with parameters and arguments, but for some reason it doesn’t work.