Hey! I’m currently making a ranking center! I need to get the gamepass info. How do I do that? This is my current code, but after what I looked in the developer docs, it all looks fine.
local a = game.Players.LocalPlayer
local b = game:GetService("MarketplaceService")
local c = script.Parent.Parent.Config.GamepassID.Value
local d = script.Parent.Parent.Config.RankID.Value
local e = b:GetProductInfo(c)
script.Parent.Parent.TextButton.Text = e.Name.." - R$ "..e.PriceInRobux
script.Parent.MouseButton1Click:Connect(function()
if b:UserOwnsGamePassAsync(a.UserId,c) then
game.ReplicatedStorage.Requests.ReqRR215F:FireServer(c, d)
else
b:PromptGamePassPurchase(a,c)
end
end)
That’s not working for 1 reason. You can’t get Gamepass/DevProduct information via Client. You need to do this via Server. Luckly, You can easily do that using RemoteFunctions. (Article about it is around at the middle of the page)
I have made a new (and fixed) version of your script! Let me know if it works! (P.S: Insert a RemoteFunction inside ReplicatedStorage named “GetGamepassInformaton” without the strings, Otherwise it won’t work)
-- ServerScript, Inside ServerScriptService
-- Variables
local MarketPlaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GetGamepassInformation = ReplicatedStorage:WaitForChild("GetGamepassInformation")
-- Main
GetGamepassInformation.OnServerInvoke = function(Player, AssetID, InfoType)
-- We're gonna return back to the Client the ProductInfo
return MarketPlaceService:GetProductInfo(AssetID, InfoType)
end
-- ClientScript, Replace the code in your current Client Gui
-- Script to this one below.
-- Variables
local MarketPlaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local GetGamepassInformation = ReplicatedStorage:WaitForChild("GetGamepassInformation")
local LocalPlayer = Players.LocalPlayer
local GamePassID = script.Parent.Parent.Config.GamepassID.Value
local RankID = script.Parent.Parent.Config.RankID.Value
local Success, GamepassInformation = pcall(function()
-- We're gonna request the Server to give us the GamepassData
-- First argument is the ID of the Gamepass, And the second one is
-- The info type, Since it's a gamepass, You're gonna need to use
-- Enum.InfoType.Gamepass, But if it's a DevProduct, You can use Enum.InfoType.Product.
return GetGamepassInformation:InvokeServer(GamePassID, Enum.InfoType.GamePass)
end)
if Success and GamepassInformation then
script.Parent.Parent.TextButton.Text = GamepassInformation.Name.." - R$ "..tostring(GamepassInformation.PriceInRobux)
else
script.Parent.Parent.TextButton.Text = "Error while requesting Gamepass Information."
end
script.Parent.MouseButton1Click:Connect(function()
if MarketPlaceService:UserOwnsGamePassAsync(LocalPlayer.UserId, GamePassID) then
ReplicatedStorage:WaitForChild("Requests").ReqRR215F:FireServer(GamePassID, RankID)
else
MarketPlaceService:PromptGamePassPurchase(LocalPlayer, GamePassID)
end
end)
I don’t understand why developers are saying you can’t get asset information from the client? You guys need to do some testing to avoid providing wrong information or ask for more context from the OP. @Forummer had the correct answer from the start. Using a remote just to fetch game pass information is entirely unnecessary use of remotes for this use case.
Repro LocalScript in ReplicatedFirst:
local MarketplaceService = game:GetService("MarketplaceService")
local success, info = pcall(function ()
return MarketplaceService:GetProductInfo(2057535, Enum.InfoType.GamePass)
end)
if success then
print(info)
else
warn(info)
end
If something doesn’t work, please reply with context instead of expecting people to spoonfeed you fixed code. Extra information wasn’t given when asked which makes it more difficult to properly help you.