script.Parent.MouseButton1Click:Connect(function()
if script.Parent.Parent.Type.Text == (Game Id) then
(Players teleport to the game)
else
(Players Stay in game)
end
end)
(It’s not a real script it’s just showing u what I want)
I want a text box so if u type a game id, like ANY game id then you wait couple seconds and get teleported to the game
but if they type a non existing game id then everyone stays in the game. how would I do this? can someone tell me/ edit my script?
I found a pretty useful function that someone created on a different post while giving it a quick google search. Try it out and see if it’s what you needed.
function IsGameValid(id)
local isgame
local success,message = pcall(function()
local gameid = game:GetService('MarketplaceService'):GetProductInfo(id)
isgame = gameid.AssetTypeId == 9
end)
return success and isgame
end
if IsGameValid(placeIdHere) then
print("valid place id")
else
print("invalid place id")
end
Replace your original conditional statement with the one the one that checks IsGameValid() from the code snippet above. It should look something like this:
local function IsGameValid(id)
local isgame
local success,message = pcall(function()
local gameid = game:GetService('MarketplaceService'):GetProductInfo(id)
isgame = gameid.AssetTypeId == 9
end)
return success and isgame
end
script.Parent.MouseButton1Click:Connect(function()
if IsGameValid(tonumber(script.Parent.Parent.Type.Text)) then
(Players teleport to the game)
else
(Players Stay in game)
end
end)
(i didn’t use a script editor to write this so sorry if there are any formatting issues or other issues with parenthesis not being closed or something)
That was just an example telling you where to put your other code since I assumed you had already made the code responsible for handling the teleport. You can read about TeleportService here. If that doesn’t help I would recommend watching a YouTube tutorial about it or something of the sort.
It’s not supposed to be a code I choose, it’s supposed to be a random code. so for example I have a text box and I type like ANY gameid code. it teleports me there. not MY code not a customized code.
I edited it for you to add some annotations to help you remember.
local function IsGameValid(id)
local isgame
local success,message = pcall(function()
local gameid = game:GetService('MarketplaceService'):GetProductInfo(id)
isgame = gameid.AssetTypeId == 9
end)
return success and isgame
end
script.Parent.MouseButton1Click:Connect(function()
if IsGameValid(tonumber(script.Parent.Parent.Type.Text)) then --this line is what checks if the place ID is valid or not
--if it is valid, teleport player here
else
--if it is not valid, send some form of error message to them? whatever you want
end
end)
I don’t think you guys get what I’m saying. Whatever gameId they enter in the textbox and then when they click enter text button then it teleports them to the game they entered
The code @azlentic provided is to help you get started. You have to script the part that teleports the players to the place. They also provided you a link to the TeleportService documentation.