I’m trying to make a script that generates a random roblox gamepass, however I’m assuming there are restrictions. Is there any other workaround? this is what I have so far.
local button = script.Parent
local rankLabel = script.Parent.Parent.RankName
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local gamepassIds = {}
local lastGamepassId = nil
math.randomseed(tick())
local function getNewGamepassId()
local newId
repeat
newId = gamepassIds[math.random(1, #gamepassIds)]
until newId ~= lastGamepassId
lastGamepassId = newId
return newId
end
local function updateGamepassName()
local Gamepass_Id = getNewGamepassId()
local success, productInfo = pcall(function()
return MarketplaceService:GetProductInfo(Gamepass_Id, Enum.InfoType.GamePass)
end)
if success then
local fadeOut = TweenService:Create(rankLabel, TweenInfo.new(1), {TextTransparency = 1})
fadeOut:Play()
fadeOut.Completed:Wait()
rankLabel.Text = productInfo.Name
local fadeIn = TweenService:Create(rankLabel, TweenInfo.new(1), {TextTransparency = 0})
fadeIn:Play()
else
print("Failed to retrieve gamepass info for ID:", Gamepass_Id)
end
end
local function Click()
local player = Players.LocalPlayer
if player then
local Gamepass_Id = getNewGamepassId()
MarketplaceService:PromptPurchase(player, Gamepass_Id)
end
end
task.spawn(function()
while true do
updateGamepassName()
task.wait(3)
end
end)
button.MouseButton1Click:Connect(Click)
button.TouchTap:Connect(Click)
--Original script by 4slgy, Thanks OverlyAmbitious