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

How to fix an error message if a ID is wrong that it displays a message?

Asked by
hokyboy 270 Moderation Voter
5 years ago
01local ID = script.Parent.Parent.IdHolder.Text -- Getss the text
02local InsertService = game:GetService("InsertService")
03 
04script.Parent.MouseButton1Click:Connect(function()
05local Model = InsertService:LoadAsset(tonumber(ID))  -- Transforms text into a number
06local NewModel = Model:GetChildren()[1]
07NewModel.Parent = workspace
08Model:Destroy()
09script.Parent.Parent.Display.Text = "Sucsess"
10end)
11else
12    script.Parent.Parent.Display.Text = "Error Loading Map,Right Id?"
13end)

1 answer

Log in to vote
1
Answered by 5 years ago

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:

01local InsertService = game:GetService("InsertService")
02local remoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
03 
04script.Parent.MouseButton1Click:Connect(function()
05    local ID = script.Parent.Parent.IdHolder.Text -- Gets the text
06    if tonumber(ID) then --Checks if it is a number
07        remoteEvent:FireServer(ID)
08        script.Parent.Parent.Display.Text = "Success"
09    else
10        print("Not a number!")
11    end
12end)

Also another note, localscripts cant load assets, so you have to have a remote event in ReplicatedStorage and a script in ServerScriptService

Server Script:

1game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent").OnServerEvent:Connect(function(ID)
2    local Model = InsertService:LoadAsset(tonumber(ID))  -- Transforms text into a number
3    local NewModel = Model:GetChildren()[1]
4    NewModel.Parent = workspace
5    Model:Destroy()
6end)

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!

Ad

Answer this question