How can I detect if text from a textBox is equal to a game id?

Hello! I am trying to make something where if you put a game id (ex: 1111111) into a textbox it can check if the game exists and if it does then it will print the game’s name. Any ideas?
my code so far is:

script.Parent.MouseButton1Click:Connect(function(plr)
	if textBox.Text ~= "" then
		if not textBox.Text:find(" ") then
			if textBox.Text:find("1") or textBox.Text:find("2") or textBox.Text:find("3") or textBox.Text:find("4") or textBox.Text:find("5") or textBox.Text:find("6") or textBox.Text:find("7") or textBox.Text:find("8") or textBox.Text:find("9") or textBox.Text:find("0") then
				local url = textBox.Text
			  		
				game.ReplicatedStorage.EnterEvent:FireServer(plr, url)
			else
				textBox.Text = ""
				textBox.PlaceholderText = "Invalid game id, try removing spaces, periods, etc."
				wait(3)
				textBox.PlaceholderText = "Put game id here."
			end
		else
			textBox.Text = ""
			textBox.PlaceholderText = "Invalid game id, try removing spaces, periods, etc."
			wait(3)
			textBox.PlaceholderText = "Put game id here."
		end
	else
		textBox.Text = ""
		textBox.PlaceholderText = "Invalid game id, try removing spaces, periods, etc."
		wait(3)
		textBox.PlaceholderText = "Put game id here."
	end
end)```
1 Like

here’s a better way to get rid of spaces and check if there is numbers

script.Parent.MouseButton1Click:Connect(function()
local CheckForNumbers = tonumber(textBox.Text)

local CheckForWhiteSpaces = string.gsub(textBox.Text,"%s","")

if #CheckForWhiteSpaces >= 1 and CheckForNumbers then
pcall(function()
local GameID = game:GetService("MarketplaceService"):GetProductInfo(textBox.Text)

if GameID then
print(GameID.Name)

end
end)
end
1 Like

The way you check get a game’s name is by

local marketplaceService = game:GetService("MarketplaceService")

local placeId = 606849621

local isSuccessful, info = pcall(marketplaceService.GetProductInfo, marketplaceService, placeId)
if isSuccessful then
    print(info.Name) --jailbreak
end

And to check for the textbox do

if tonumber(textBox.text) then --means its numbers
	local marketplaceService = game:GetService("MarketplaceService")

	local placeId = tonumber(textBox.text)

	local isSuccessful, info = pcall(marketplaceService.GetProductInfo, marketplaceService, placeId)
	if isSuccessful then
  	  print(info.Name)
	end
end
2 Likes

Thank you, I will use this to clean up the script.

2 Likes

Thank you, this works. I am so grateful for this!

2 Likes

this code works too but anyways lol

2 Likes

Your welcome, glad I was able to help!

2 Likes

Oh also one thing, I just tried to get info.Name on the server but it says: ServerScriptService.GameSetHandler:14: attempt to index nil with 'Name'
My server code is:

local http = game:GetService("HttpService")
local gamesScroller = game.Workspace.Stand.GamesPart.GamesGui.GamesScroller
local newButton = script.GameButton

game.ReplicatedStorage.EnterEvent.OnServerEvent:Connect(function(plr, info)
	
	local newButton = script.GameButton:Clone()

	newButton.Parent = gamesScroller

	gamesScroller.CanvasSize = UDim2.new(0, gamesScroller.UIListLayout.AbsoluteContentSize.X, 0, 0)
	newButton.Text = info.Name
	print(info.Name)
end)```
1 Like

Please fix the formats i cant understand whats written

2 Likes

I’ve fixed the formats now. ```````

1 Like

I think you cant actually pass the info as it is, pass the name / what you want from it

Ohh, ok. That makes more sense, thank you!

1 Like

I have tried 2 different methods on the server and newButton.Text = tostring(GameName) prints nil, and if I remove the tostring it errors: Unable to assign property Text. string expected, got nil I am sending the server the info with: ```

local GameName = info.Name
					event:FireServer(plr, GameName)```
local Game = game
local Script = script
local TextBox = Script.Parent

local function OnTextBoxChanged()
	if TextBox.Text == tostring(Game.GameId) then
		print("You typed the game's universe ID.")
	elseif TextBox.Text == tostring(Game.PlaceId) then
		print("You typed the game's place ID.")
	end
end

TextBox:GetPropertyChangedSignal("Text"):Connect(OnTextBoxChanged)

If you just want to check if a textbox’s text equals the game’s universe ID/place ID.

I think you are firing from server to client which wont work, show me your full code for this.

My local script is:

local textBox = script.Parent.Parent.TextBox
local http = game:GetService("HttpService")
local event = game.ReplicatedStorage.EnterEvent

script.Parent.MouseButton1Click:Connect(function(plr)
	if textBox.Text ~= "" then
		if not textBox.Text:find(" ") then
			if tonumber(textBox.text) then
				local marketplaceService = game:GetService("MarketplaceService")

				local placeId = tonumber(textBox.text)

				local isSuccessful, info = pcall(marketplaceService.GetProductInfo, marketplaceService, placeId)
				if isSuccessful then
					local GameName = info.Name
					event:FireServer(plr, GameName)
				end
			else
				textBox.Text = ""
				textBox.PlaceholderText = "Invalid game id, try removing spaces, periods, etc."
				wait(3)
				textBox.PlaceholderText = "Put game id here."
			end
		else
			textBox.Text = ""
			textBox.PlaceholderText = "Invalid game id, try removing spaces, periods, etc."
			wait(3)
			textBox.PlaceholderText = "Put game id here."
		end
	else
		textBox.Text = ""
		textBox.PlaceholderText = "Invalid game id, try removing spaces, periods, etc."
		wait(3)
		textBox.PlaceholderText = "Put game id here."
	end
end)

and my serverscript is:

local http = game:GetService("HttpService")
local gamesScroller = game.Workspace.Stand.GamesPart.GamesGui.GamesScroller
local newButton = script.GameButton

game.ReplicatedStorage.EnterEvent.OnServerEvent:Connect(function(plr, GameName)
	local newButton = script.GameButton:Clone()

	newButton.Parent = gamesScroller

	gamesScroller.CanvasSize = UDim2.new(0, gamesScroller.UIListLayout.AbsoluteContentSize.X, 0, 0)
	newButton.Text = ""
	newButton.Text = GameName
	print(GameName)
end)```

This could work but I want to see if they press a button, but if I can’t figure the other option out I’ll use this!

GetPropertyChangedSignal(“Text”) will fire everytime the Text changes.

I just realised I can’t use this script because I want to make a surfaceGui appear on a specific player’s stand.

Alright, I have found the fix, I was supposed to fireserver(textboxgamename) and .onserverevent was supposed to have the plr and textboxgamename argument, meanwhile the client didn’t need to have the plr argument. Thank you @ayoub50 @Forummer @msix29 for helping me yesterday!

2 Likes