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)```
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
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
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)```
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.
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)```
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!