Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Insert model by clicking on a textbutton?

Asked by
Rdumb1 4
5 years ago

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.

0
And I copy and pasted the first line from the roblox wiki because I'm not really experienced with scripting. Rdumb1 4 — 5y
0
is it local? DeceptiveCaster 3761 — 5y
0
nope. Rdumb1 4 — 5y
0
it should be local DeceptiveCaster 3761 — 5y
View all comments (2 more)
0
k. Lemme test it. Rdumb1 4 — 5y
0
and when its local, its not working. Rdumb1 4 — 5y

3 answers

Log in to vote
0
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
5 years ago

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:

LocalScript

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)

Server Script

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

0
What about textbutton? Rdumb1 4 — 5y
0
and where do I put the scripts? Rdumb1 4 — 5y
0
If you don't know how to do that, I advise you to read some beginner wiki tutorials before trying to create more difficult scripts like this one Amiaa16 3227 — 5y
0
I couldn't find any that are related to this. Rdumb1 4 — 5y
Ad
Log in to vote
0
Answered by
BRAEGON -8
5 years ago

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?

Log in to vote
0
Answered by
danklua 72
3 years ago

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.

Answer this question