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)
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.
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)
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.
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)