local ID = script.Parent.Parent.IdHolder.Text -- Getss the text local InsertService = game:GetService("InsertService") script.Parent.MouseButton1Click:Connect(function() local Model = InsertService:LoadAsset(tonumber(ID)) -- Transforms text into a number local NewModel = Model:GetChildren()[1] NewModel.Parent = workspace Model:Destroy() script.Parent.Parent.Display.Text = "Sucsess" end) else script.Parent.Parent.Display.Text = "Error Loading Map,Right Id?" end)
The problem is you need to check the text every time you click the thing, also you need to check if the ID is a number.
Local Script:
local InsertService = game:GetService("InsertService") local remoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent") script.Parent.MouseButton1Click:Connect(function() local ID = script.Parent.Parent.IdHolder.Text -- Gets the text if tonumber(ID) then --Checks if it is a number remoteEvent:FireServer(ID) script.Parent.Parent.Display.Text = "Success" else print("Not a number!") end end)
Also another note, localscripts cant load assets, so you have to have a remote event in ReplicatedStorage and a script in ServerScriptService
Server Script:
game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent").OnServerEvent:Connect(function(ID) local Model = InsertService:LoadAsset(tonumber(ID)) -- Transforms text into a number local NewModel = Model:GetChildren()[1] NewModel.Parent = workspace Model:Destroy() end)
And it should work!
If you want to learn more about remoteevents then go here: https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events
I hope this helped you!