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

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:

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!

Ad

Answer this question