How could I do this?

So I have this script

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?

2 Likes

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
1 Like

I don’t understand, could you explain more? :happy2: thank you.

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)

image

You are supposed to replace the stuff inside the if statements with your own code.

2 Likes

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 meant in the block, not in the condition.

if true then
    -- here
end

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

here’s a example:

So if I enter the game id of piggy in the textbox and I click the text button aka (enter)

it will wait 3 seconds ad it will teleport me to that game.

We understand what you are saying.

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.

  1. game:GetService(‘TeleportService’):Teleport?

Sorry Im very confused and tired

If you are only teleporting one player, yes.

how would I teleport everyone in the server?

You would use TeleportService:TeleportPartyAsync().

image

You have to import TeleportService. At the top of your script, add this:

local TeleportService = Game:GetService("TeleportService")

Oh okay thank you for telling me.