So I'm trying to make a gui that could insert something just for fun, I'm new to lua scripting and I don't know what to do, but here's what I did.
script.Parent.MouseButton1Click:connect(function() InsertService:LoadAsset("257489726") end)
Please correct and tell me whats wrong?
And I put the script in the textbutton.
Hi. In order to do that, you need to pass the model id to the server via RemoteEvents, as only server can insert assets into the game. (If you don't know how remote events work, you should read about Filtering Enabled here, and about remotes themselves here)
I'm going to assume you want to insert models of the ids you type into a TextBox in some gui.
To do that, create a remote event under ReplicatedStorage
, name it as you wish, but I'll just call it "RemoteEvent", and then use it to pass the model id to the server once the player clicks your button. Example:
local remote = game.ReplicatedStorage:WaitForChild("RemoteEvent") local gui = script.Parent local button = gui.Button local tb = gui.TextBox button.MouseButton1Click:Connect(function() --use uppercase Connect, not connect remote:FireServer(tb.Text) --pass the text of the textbox to the server via the remote end)
local remote = game.ReplicatedStorage.RemoteEvent remote.OnServerEvent:Connect(function(plr, id) local model = game:GetService("InsertService"):LoadAsset(id) model.Parent = workspace end)
Don't forget to implement a proper security against exploiters. Also be aware of the restrictions when it comes to inserting models (you can't insert models that aren't in your inventory or don't belong to roblox).
It's not really an answer but couldn't you just insert it in the studio and put it in Server Storage and from there you could simply move it to the workspace and to whatever position you wanted?
Well, theres one problem with this.. First I was trying out whether which value type this needs. I tried this:
local value = script.Parent.Value.Value game:GetService("InsertService"):LoadAsset("rbxasset://"..value) --and-- game:GetService("InsertService"):LoadAsset(value)
so im wondering if somebody could fix this because when i scripted the script above in returns with this error: "Unable to cast string to int64" If you could help that would be great. Also the model it inserts is a model the owner owns.