Need help with getting a number from a textbox when textbutton clicked (surfacegui related)

I’m trying to get a number value from when a number is inputted inside a textbox, once the player clicks the textbutton, the value is then checked by InsertService to find an item from the catalog to be placed in the dummy.

local TextBoxPants = script.Parent.SurfaceGui2.Frame.PantsTextBox
local TextButtonPants = script.Parent.SurfaceGui2.Frame.PantsTextButton
local Id = tonumber((TextBoxPants.Text)) 
local InsertService = game:GetService("InsertService")

TextButtonPants.MouseButton1Click:Connect(function(pant)
	InsertService:LoadAsset(Id).Parent = workspace.Stands.StandModel1.Stage.Stand4.Dummy.Pants.PantsTemplate
end)

Thanks!

Define the Id inside of the MouseButton1Click function

local TextBoxPants = script.Parent.SurfaceGui2.Frame.PantsTextBox
local TextButtonPants = script.Parent.SurfaceGui2.Frame.PantsTextButton
local InsertService = game:GetService("InsertService")

TextButtonPants.MouseButton1Click:Connect(function(pant)
	local Id = tonumber((TextBoxPants.Text)) 
	InsertService:LoadAsset(Id).Parent = workspace.Stands.StandModel1.Stage.Stand4.Dummy.Pants.PantsTemplate
end)

I got an error for Line 13
" Argument 1 missing or nil"

Sorry for the late reply. The issue is probably that this is a server script. What the client types into a textbox only shows on that client. Have the client detect the click and fire a remote event with the id, and have the server then load that asset. Make sure to have some sanity checks though.

1 Like