Help with Insert Model Script

Hi! I need some help.

So, I am making a GUI where you type the Asset ID into the TextBox, then click ‘SPAWN’, and the Model will Load In.
However, I am getting the Error:

  19:29:31.932  Unable to cast Instance to int64  -  Server - Script:5

Is this because I am doing two scripts?

Script 1, changing a NumberValue to the inserted ID:

local value = script.Parent

script.Parent.Parent.TextButton.MouseButton1Click:Connect(function()
	value.Value = script.Parent.Parent.IDinsert.Text
end)

Script 2, Inserting the Model:

InsertSevice = game:GetService("InsertService")
local ID = script.Parent.ID
script.Parent.TextButton.MouseButton1Click:Connect(function()
	wait(1)
	local Model = InsertSevice:LoadAsset(ID)
	Model.Parent = workspace
end)

The Constant called ID is the Number Value.

Thanks, AridOats.

1 Like

Use tonumber to change the Text to a number. Like this:

local value = script.Parent

script.Parent.Parent.TextButton.MouseButton1Click:Connect(function()
	local ID = tonumber(script.Parent.Parent.IDinsert.Text)
	if ID == nil then
		return
	end
	value.Value = ID
end)

Also added a check to see if it’s a number so it doesn’t change anything if it isn’t.

1 Like

This is for… script 1 or 2?
Thankyou for the quick response, btw.

This is for script 1 where you change the value.

1 Like