Problems with choosing random game script

Hello DevForum. I’ve got a problem. First of all, I’m gonna explain the game. The game is basically a game where you generate random games on Roblox. Works ‘perfectly’, if we don’t include the next problems:

  • When taking too much time, It’s gonna give an error (HTTP) because It’s calling functions too many times. I wanted so it could just warn not error, because then you would need to join another server
  • Overall takes too much time, even tho it always works…
  • Can’t never get number of favorites and votes.

1. What do you want to achieve? Keep it simple and clear!

I want to achieve a system where I can generate random games on Roblox where you can join them, with purpose of making people play random games choosen and not decise by them selfs. I want a clear system, like mine but that doesn’t take too much time and that has more ‘debugs’ so it’s rare to output an actual error, rather than just a warning.
And also I want one that don’t output in favorites and votes label always ‘N/A’, since it always doesn’t suceed (in the pcall function).
I want someone to give an url that actually works and isn’t outdated, basically I mean a proxy.

2. What is the issue? Include screenshots / videos if possible!

It takes too much time too choose one! If you have pacience, then It’s ok. But this game is gonna be public, and It’s pretty reasonable that users won’t like that.
And also the fact that the part of the favorites and rating votes label are always set to ‘N/A’, meaning that it never suceeds. It always prints out a HTTP 403 (forbidden) error
It’s not about the design itself, it’s just about a script, but here’s a script to give you an idea of what I’m doing at this moment:

image
(Take in mind that the things on the screen are not always visible like on the image, the image was captured on studio, not play mode)

3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

Yes, I have. Some even helped, like the IsGamePublic() and others. Thank you Devforum.
But I think those topics are old or just don’t work that well anymore, especially the s2,e2 pcall, which always outputs not s. It’s not that big of a deal, but it would be cool if the game had that. I’ve also tried using game.roblox.com and not game.roproxy.com but it still says that I have no permission or something like that…
About the taking too much time, I’ve tried adding an higher interval in math.random, including the minimum and the maximum. I’ve tried changing wait() to task.wait() since there are people saying It’s faster and more updated.

UPDATE:

I’ve realised that it’s the IsGamePublic() function. But without it, the teleportation most times don’t work, since majority of games are private or only for friends.

-----------------------------------

In conclusion, I want a script that’s faster, doesn’t take too much time, that doesn’t output errors, but rather warnings or just normal prints (so the script doesn’t stop), and I want one where It’s possible to get favorites and public rating (in %, up votes and down votes).
So, after yapping, I’m gonna provide you the script:

local ui = script.Parent:WaitForChild("SurfaceGui")
local MainFrame = ui.Frame
local line = MainFrame.line
local lineBar = line.bar
local gameImage = MainFrame.PlaceImg
local selectingLabel = MainFrame.SelectingLabel
local gameName = MainFrame.PlaceNameAndCreator
local likesLabel = MainFrame.LikesLabel
local visitsLabel = MainFrame.VisitsLabel
local descriptionLabel = MainFrame.DescriptionLabel
local favoritesLabel = MainFrame.FavoritesLabel
local genreLabel = MainFrame.GenreLabel
local playingLabel = MainFrame.PlayingLabel
local yearLabel = MainFrame.YearLabel

local timerSound = script.Parent:WaitForChild("timer_beep")
local selectedSound = script.Parent:WaitForChild("WallJump")

local TPS = game:GetService("TeleportService")
local MarketplaceService = game:GetService("MarketplaceService")
local http = game:GetService("HttpService")

function getUniverseData(universeId)
	local response = http:GetAsync("https://games.roproxy.com/v1/games?universeIds="..universeId)
	return http:JSONDecode(response)
end

function getCreatorPublicGames(creatorType, creatorId)
	local endpoint = (creatorType == "User" and "https://games.roproxy.com/v2/users/%s/games?accessFilter=2&limit=50" or "https://games.roproxy.com/v2/groups/%s/games?accessFilter=2&limit=50")
	local response = http:GetAsync(string.format(endpoint, creatorId))
	return http:JSONDecode(response)
end

function isGamePublic(universeId)
	local creatorData = getUniverseData(universeId).data[1].creator

	local creatorGames = getCreatorPublicGames(creatorData.type, creatorData.id)

	for i, gameData in pairs(creatorGames.data) do
		if gameData.id == universeId then return true end
	end

	return false
end


local function IsNameValid(gameName)
	local invalidKeywords = {"place", "normal"}
	for _, keyword in pairs(invalidKeywords) do
		if string.find(gameName:lower(), keyword) then
			return false
		end
	end
	return true
end

local function IsGameValid(id)
	local success, gameInfo = pcall(function()
		return MarketplaceService:GetProductInfo(id)
	end)

	if success then
		return gameInfo.AssetTypeId == 9
	else
		return false
	end
end

local secondsCountdown = 7
local imageThread

MainFrame.Visible = true
task.spawn(function()
	while true do
		line.Visible = false
		gameImage.Visible = false
		selectingLabel.Visible = true
		gameName.Visible = false
		favoritesLabel.Visible = false
		likesLabel.Visible = false
		genreLabel.Visible = false
		visitsLabel.Visible = false
		descriptionLabel.Visible = false
		playingLabel.Visible = false
		yearLabel.Visible = false

		local foundGame = false
		local RandomID
		local info

		repeat
			task.wait(.2)
			RandomID = math.random(500000, 1400000000)

			if IsGameValid(RandomID) then
				local success, errorMsg = pcall(function()
					info = MarketplaceService:GetProductInfo(RandomID)
				end)

				if (success == true) and (info.AssetTypeId == 9) and not string.find(info.Description, "This is your very" and "creation") and info.Name ~= info.Creator.Name.."'s Place" and info.Name ~= info.Creator.Name.."'s City" then
					if IsNameValid(info.Name) then
						print("Valid game found: " .. info.Name)
						foundGame = true
						break
					end
				end
			end
		until foundGame and IsNameValid(info.Name)

		local furtherInfo
		local getUniverseId
		local s1, e1 = pcall(function()
			getUniverseId = http:JSONDecode(http:GetAsync("https://apis.roproxy.com/universes/v1/places/"..RandomID.."/universe"))
			getUniverseId = getUniverseId.universeId
			print(getUniverseId)

			local data = http:JSONDecode(http:GetAsync("https://games.roproxy.com/v1/games?universeIds="..getUniverseId))
			furtherInfo = data.data[1]
		end)

		if not s1 then
			warn(e1)
			continue 
		end
		if getUniverseId ~= nil then
			if RandomID ~= furtherInfo.rootPlaceId then
				warn("RandomID is not the root place! Skipping this one.")
				continue
			end
			if not isGamePublic(getUniverseId) then
				continue
			end
		end

		local __ = "nil"
		if info.Creator.Name ~= nil then
			__ = "@" .. info.Creator.Name
		end
		gameName.Text = info.Name.."\n(by: "..__..")"

		descriptionLabel.Text = "🗒️ DESCRIPTION:\n"..info.Description
		visitsLabel.Text = "👤 VISITS:\n"..tostring(furtherInfo.visits)
		genreLabel.Text = "⚔️ GENRE:\n"..tostring(furtherInfo.genre)
		playingLabel.Text = "▶️ PLAYING:\n"..tostring(furtherInfo.playing)
		yearLabel.Text = "YEAR:\n"..string.split(furtherInfo.created, "-")[1]
		local Icon = "rbxthumb://type=GameIcon&id="..getUniverseId.."&w=150&h=150"
		gameImage.Image = Icon

		local favouriteData
		local ratingData
		local s2, e2 = pcall(function()
			favouriteData = http:JSONDecode(http:GetAsync("https://games.roproxy.com/v1/games/"..getUniverseId.."/favorites/count"))
			ratingData = http:JSONDecode(http:GetAsync("https://games.roproxy.com/v1/games/votes?universeIds="..getUniverseId))
		end)

		if s2 then
			favoritesLabel.Text = "FAVORITES:\n"..favouriteData.favoritesCount
			local upvotes = ratingData.data[1].upVotes
			local downvotes = ratingData.data[1].downVotes
			local totalRating = 0
			if upvotes + downvotes > 0 then
				totalRating = math.floor(upvotes / (upvotes + downvotes) * 100)
			end
			likesLabel.Text = "RATING:\n"..totalRating.."%"
		else
			warn(e2)
			favoritesLabel.Text = "FAVORITES:\nN/A"
			likesLabel.Text = "RATING:\nN/A"
		end
		script.Parent.id.Value = RandomID

		line.Visible = true
		gameImage.Visible = true
		selectingLabel.Visible = false
		gameName.Visible = true
		favoritesLabel.Visible = true
		likesLabel.Visible = true
		genreLabel.Visible = true
		visitsLabel.Visible = true
		descriptionLabel.Visible = true
		playingLabel.Visible = true
		yearLabel.Visible = true

		selectedSound:Play()

		lineBar.Size = UDim2.new(0,0,1,0)
		lineBar.TextLabel.Text = tostring(secondsCountdown) .. " SECONDS LEFT"
		local inCounter = secondsCountdown
		repeat
			wait(1)
			inCounter -= 1
			local xScale = 1 - (inCounter / secondsCountdown)

			game:GetService("TweenService"):Create(lineBar, TweenInfo.new(.5), {Size = UDim2.new(xScale, 0, 1, 0)}):Play()

			if inCounter <= 5 then
				timerSound:Play()
			end
			lineBar.TextLabel.Text = tostring(inCounter) .. " SECONDS LEFT"
		until inCounter <= 0

		for _, player in ipairs(game.Players:GetPlayers()) do
			if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
				local rootPart = player.Character.HumanoidRootPart
				local rayOrigin = rootPart.Position
				local rayDirection = Vector3.new(0, -5, 0)

				local raycastParams = RaycastParams.new()
				raycastParams.FilterDescendantsInstances = {player.Character}
				raycastParams.FilterType = Enum.RaycastFilterType.Blacklist

				local rayResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)

				if rayResult and rayResult.Instance and rayResult.Instance == game.Workspace.JoinBlockSinglePlayer then
					local hum = player.Character:FindFirstChild("Humanoid")
					if hum then
						hum.WalkSpeed = 0
					end

					task.spawn(function()
						local ui = player.PlayerGui:FindFirstChild("LoadingUI")
						local frame
						local label
						if ui then
							frame = ui.Frame
							label = frame.TextLabel
							label.Text = "TELEPORTING TO \""..info.Name.."\".."
							game:GetService("TweenService"):Create(frame, TweenInfo.new(2), {BackgroundTransparency = 0}):Play()
							local a = game:GetService("TweenService"):Create(label, TweenInfo.new(2), {TextTransparency = 0})
							a:Play()
							a.Completed:Wait()
						end
						local s,e = pcall(function()
							TPS:Teleport(RandomID, player, nil, ui)
						end)
					end)
				end
			end
		end
		task.wait(1)
	end
end)

TPS.TeleportInitFailed:Connect(function(player)
	local hum = player.Character:FindFirstChild("Humanoid")
	if hum then
		hum.WalkSpeed = 16
	end
	local ui = player.PlayerGui:FindFirstChild("LoadingUI")
	local frame
	local label
	if ui then
		frame = ui.Frame
		label = frame.TextLabel
	end
	frame.BackgroundTransparency =1
	label.TextTransparency = 1
end)

At best, anything else works, only the three first topics I mentioned earlier don’t

If you don’t understand what I mean, please reply for an explanation. I’ve tried explaining my best.
Here’s the three topics so you don’t have to go back to the beginning.

Keep in mind everything else works perfectly.

1 Like

So from what I read, you are looking for a way to obtain information on a select (well, random, but select works too) game? If so, you aren’t obligated to use a proxy. MarketplaceService has a function titled GetProductInfo, which works for games.

1 Like

Yes, but to get favorites, rating/votes, genre, visits, it’s necessary
But everything works at that point. But the part of the favorites and playing don’t.

But about this I don’t worry too much. It’s more about it taking too much time

sorry!! i seem to have accidentally quoted the post

Oh! You were already using it, and you are right, it doesn’t get those

Can you try using id 2323222 specifically? Comment out the math.random() for now
https://games.roproxy.com/v1/games/2323222/favorites/count works

Hope you find out what went wrong.

1 Like

I’m sorry. I didn’t really understand what you meant. Can you specify?
You want me to remove the math.random for now and use 2323222 as RandomID for now?
Is that it?

1 Like

Yes! Also you should comment out the “place” check, as the games titled hakjfg’s Place

Well shouldnt that be normal? you iterate over millions of ids and most of which doesnt follow a specific criteria

I did everything you said.
I think it doesnt detect that ID. I have an idea, what about game.PlaceId instead of that id?
Or am i misunderstanding what you’re trying to do with the id?

True, but I want one that is very restricted so the transportation (transport service ) always suceeds.

Also, forgot to mention that without the root part solution it would always find a random popular game universe id (in mose cases)

With game.PlaceId it works like expected with math.random (if it was faster)
image

So the problem is about taking too much time when theres math.random
And I removed favorites and the other thing (i dont remember), but that are in s2,e2 pcall.
I made them visible = false

UPDATE!!

I couldn’t fix the favorites part (s2,e2 pcall),
but I managed to fix the most important one, which was taking too much time! Took me a long time to figure this technique below:

local idRanges = {
			{1, 999999},               -- 1 to 999,999
			{1000000, 1999999},        -- 1M to 1,999,999
			{2000000, 2999999},        -- 2M to 2,999,999
			{3000000, 3999999},        -- 3M to 3,999,999
			{4000000, 4999999},        -- 4M to 4,999,999
			{5000000, 5999999},        -- 5M to 5,999,999
			{6000000, 6999999},        -- 6M to 6,999,999
			{7000000, 7999999},        -- 7M to 7,999,999
			{8000000, 8999999},        -- 8M to 8,999,999
			{9000000, 9999999},        -- 9M to 9,999,999
			{10000000, 10999999},      -- 10M to 10,999,999
			{11000000, 11999999},      -- 11M to 11,999,999
			{12000000, 12999999},      -- 12M to 12,999,999
			{13000000, 13999999},      -- 13M to 13,999,999
			{14000000, 14999999},      -- 14M to 14,999,999
			{15000000, 15999999},      -- 15M to 15,999,999
			{16000000, 16999999},      -- 16M to 16,999,999
			{17000000, 17999999},      -- 17M to 17,999,999
			{18000000, 18999999},      -- 18M to 18,999,999
			{19000000, 19999999},      -- 19M to 19,999,999
			{20000000, 20999999},      -- 20M to 20,999,999
			{21000000, 21999999},      -- 21M to 21,999,999
			{22000000, 22999999},      -- 22M to 22,999,999
			{23000000, 23999999},      -- 23M to 23,999,999
			{24000000, 24999999},      -- 24M to 24,999,999
			{25000000, 25999999},      -- 25M to 25,999,999
			{26000000, 26999999},      -- 26M to 26,999,999
			{27000000, 27999999},      -- 27M to 27,999,999
			{28000000, 28999999},      -- 28M to 28,999,999
			{29000000, 29999999},      -- 29M to 29,999,999
			{30000000, 30999999},      -- 30M to 30,999,999
			{31000000, 31999999},      -- 31M to 31,999,999
			{32000000, 32999999},      -- 32M to 32,999,999
			{33000000, 33999999},      -- 33M to 33,999,999
			{34000000, 34999999},      -- 34M to 34,999,999
			{35000000, 35999999},      -- 35M to 35,999,999
			{36000000, 36999999},      -- 36M to 36,999,999
			{37000000, 37999999},      -- 37M to 37,999,999
			{38000000, 38999999},      -- 38M to 38,999,999
			{39000000, 39999999},      -- 39M to 39,999,999
			{40000000, 40999999},      -- 40M to 40,999,999
			{41000000, 41999999},      -- 41M to 41,999,999
			{42000000, 42999999},      -- 42M to 42,999,999
			{43000000, 43999999},      -- 43M to 43,999,999
			{44000000, 44999999},      -- 44M to 44,999,999
			{45000000, 45999999},      -- 45M to 45,999,999
			{46000000, 46999999},      -- 46M to 46,999,999
			{47000000, 47999999},      -- 47M to 47,999,999
			{48000000, 48999999},      -- 48M to 48,999,999
			{49000000, 49999999},      -- 49M to 49,999,999
			{50000000, 50999999},      -- 50M to 50,999,999
			{51000000, 51999999},      -- 51M to 51,999,999
			{52000000, 52999999},      -- 52M to 52,999,999
			{53000000, 53999999},      -- 53M to 53,999,999
			{54000000, 54999999},      -- 54M to 54,999,999
			{55000000, 55999999},      -- 55M to 55,999,999
			{56000000, 56999999},      -- 56M to 56,999,999
			{57000000, 57999999},      -- 57M to 57,999,999
			{58000000, 58999999},      -- 58M to 58,999,999
			{59000000, 59999999},      -- 59M to 59,999,999
			{60000000, 60999999},      -- 60M to 60,999,999
			{61000000, 61999999},      -- 61M to 61,999,999
			{62000000, 62999999},      -- 62M to 62,999,999
			{63000000, 63999999},      -- 63M to 63,999,999
			{64000000, 64999999},      -- 64M to 64,999,999
			{65000000, 65999999},      -- 65M to 65,999,999
			{66000000, 66999999},      -- 66M to 66,999,999
			{67000000, 67999999},      -- 67M to 67,999,999
			{68000000, 68999999},      -- 68M to 68,999,999
			{69000000, 69999999},      -- 69M to 69,999,999
			{70000000, 70999999},      -- 70M to 70,999,999
			{71000000, 71999999},      -- 71M to 71,999,999
			{72000000, 72999999},      -- 72M to 72,999,999
			{73000000, 73999999},      -- 73M to 73,999,999
			{74000000, 74999999},      -- 74M to 74,999,999
			{75000000, 75999999},      -- 75M to 75,999,999
			{76000000, 76999999},      -- 76M to 76,999,999
			{77000000, 77999999},      -- 77M to 77,999,999
			{78000000, 78999999},      -- 78M to 78,999,999
			{79000000, 79999999},      -- 79M to 79,999,999
			{80000000, 80999999},      -- 80M to 80,999,999
			{81000000, 81999999},      -- 81M to 81,999,999
			{82000000, 82999999},      -- 82M to 82,999,999
			{83000000, 83999999},      -- 83M to 83,999,999
			{84000000, 84999999},      -- 84M to 84,999,999
			{85000000, 85999999},      -- 85M to 85,999,999
		}

Thank you @callme_daninja for trying to help me!