Here is how to make that system!
Here are all the steps!
a) Create the ImageLabel
b) Create a LocalScript inside the ImageLabel
c) Write the script!
I’ll skip the first 2 steps I think you can do it!
Let’s make the script.
Firstly, we need to determine the services:
local MPS = game:GetService("MarketplaceService") -- We use MarketplaceService to get a Dictionary with all the information from an id
local TS = game:GetService("TeleportService") -- We use TeleportSerivce to actually teleport the player to a game/place
Now, we should write how we will know that the button is clicked.
script.Parent.MouseButton1Click:Connect(function()
end)
When the ImageLabel is clicked it will fire a function.
To get a random game id we will use math.random.
local id = math.random(1, 100000000)
But how will we check if the id that has been generated is actually a game Id? For this reason, we use MPS (MarketplaceService ) to get a dictionary (let’s say a list ) with some information that will help us check what the Id is.
To ensure we actually get an id we will put the “check” inside a pcall. (Ensuring that we can handle any errors )
local PlaceCheck
local success, whoops = pcall(function()
PlaceCheck = MPS:GetProductInfo(tonumber(id))
end)
Lastly, we need to check if the pcall returns success (so the id is actually a game id ). If it does, it will teleport the player there!
if success and PlaceCheck and PlaceCheck.AssetTypeId == 9 then
TS:Teleport(tonumber(id), game.Players.LocalPlayer)
else
id = math.random(1, 100000000)
end
*You can find more about AssetTypes here!.
Final Code
local MPS = game:GetService("MarketplaceService")
local TS = game:GetService("TeleportService")
script.Parent.MouseButton1Click:Connect(function()
local id = math.random(1, 100000000)
local PlaceCheck
local success, whoops = pcall(function()
PlaceCheck = MPS:GetProductInfo(tonumber(id))
end)
if success and PlaceCheck and PlaceCheck.AssetTypeId == 9 then
TS:Teleport(tonumber(id), game.Players.LocalPlayer)
else
id = math.random(1, 100000000)
end
end)
This text will be hidden
Hope this helped you, if you have any other questions let me know! 