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:
(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.