Hello Robloxians!
TechTeam911 here - today, I will be teaching you guys how to use the new feature of Roblox, the MarketplaceService.
What is MarketplaceService?
MarketplaceService is the new service that was unlocked by Roblox recently. It holds a variety of features that scripters can utilize to create in-game purchases (And also retrieve information about an item from the catalog.)
How do I use it?
The methods of MarketplaceService have very few limitations. The only limitation is that if you try to prompt a purchase on a guest, it'll throw you a warning asking you to avoid prompting purchases with guest users (This won't halt your script, it'll just warn you in the output.) Otherwise, there are no other main requirements.
Methods that you need to know:
PromptPurchase
GetProductInfo
PlayerOwnsAsset
PromptPurchase()
Limitations: None.
Arguments: Player,assetId,equipIfPurchased,CurrencyType
What you need to know:
In order to use PromptPurchase, you have to get the service that manages in-game transactions (MarketplaceService). To get the service, you would use this simple line. game:GetService("MarketplaceService")
What the arguments mean:
Player is player, ie: game.Players.Player1.
equipIfPurchased - if the object the player purchased is a gear item, automatically have the character equip it.
CurrencyType, specifies what desired currency (If it's for sale with that currency type) is preferred. Ie: Wanting a user to purchase an item in-game with Robux instead of Tickets. If the item is on sale for only tickets, and you try to specify Robux, it'll prompt the purchase with Tickets, and vice-versa. Two enums (1 = Robux, 2 = Tix). You can also specify which currency you want by using it's name (Ie: "Robux","Tix")
Example script:
game.Players.Players.PlayerAdded:connect(function(player) -- Player entered.
player.Chatted:connect(function(msg) -- Player spoke.
if (string.lower(msg) == "don8pl0x!") then -- See if the non-capital letter version of the message is equal to 'don8pl0x!'
game:GetService("MarketplaceService"):PromptPurchase(player,20573078) -- Prompt the player to purchase the hat 'Shaggy'.
end
end)
end)
GetProductInfo()
Limitations: Excessive requests with this method get throttled. In a nutshell, don't go getting product info for an item every available second, otherwise it'll prevent you from pulling info for a while.
Arguments: assetId
What you need to know:
This is a method that advanced scripters can utilize to pull the product info on an item (Ie: Name, price, date created, etc.) directly from the website.
Warning: Geek language incoming!
When you use GetProductInfo, it returns the information in JSON format on the item you used the method on. By JSON format, I mean that all the data that is returned is in a table for easy access.
Returns: AssetId,ProductId,Name,Description,AssetTypeId,CreatorId,Name,Created,Updated,PriceInRobux,PriceInTickets,Sales,IsNew,IsForSale,IsPublicDomain,IsLimited,IsLimitedUnique,Remaining,MinimumMembershipLevel, and ContentRatingTypeId.
Breaking down what GetProductInfo returns.
AssetId: The AssetId of the product you looked up.
ProductId: Not used by users.
Name: Self-explanatory, returns the name of the item.
Description: Returns the description of the item.
AssetTypeId: Returns an enum that signifies what type of item the asset you looked up is.
CreatorId: Returns the userId of the creator of the asset.
Name: Name of the creator.
Created: Returns YYYY-MM-DD + TT:TT:TT as to when the item was created.
Updated: Returns YYYY-MM-DD + TT:TT:TT as to when the item was last updated.
PriceInRobux: Returns how much the item is priced at in Robux, returns null if it isn't for sale in Robux.
PriceInTickets: Returns how much the item is priced at in Tickets, returns null if it isn't for sale in Tickets.
IsNew: Returns a bool as to whether the item is new or not.
IsForSale: Returns a bool as to whether or not the item is for sale.
IsPublicDomain: Returns a bool as to whether the item is free to take or not.
IsLimited: Returns a bool as to whether the item is limited or not.
IsLimitedUnique: Returns a bool as to whether the item is LimitedU or not.
Remaining: Returns how many (If the item is limited/limitedU) copies of the item are remaining, otherwise returns null.
MinimumMembershipLevel: Returns a number as to what minimum membership level is required to purchase the item.
ContentRatingTypeId: Returns 0 if the item is under 13+, 1 if it is over 13+.
Example script: print(game:GetService("MarketplaceService"):GetProductInfo(20573078)) -- Run in the command bar with the output window open.
PlayerOwnsAsset()
Arguments: Player,assetId
What you need to know:
This is a simple method that tells you if a player owns an item or not.
Player is player, ie: game.Players.Player1
assetId is the assetId of an item you want to see if the player owns or not.
Example script:
game.Players.PlayerAdded:connect(function(player) -- Player entered game.
if game:GetService("MarketplaceService"):PlayerOwnsAsset(player,20573078) -- Does the player own Shaggy?
player:Destroy() --NOOB!!!
print("Noob!!!")
else
print("Ok, he's not a noob.")
end
end)
That's it for the new MarketplaceService - there are more methods and features of the MarketplaceService for more advanced scripters, but these are the basic three methods that you should know.
Thanks for reading! Feel free to PM me on Roblox if you have any questions.
~Tech
WARNING: We are currently transitioning getProductInfo to return a table instead of JSON. On windows and mac it should be giving you a table already, on IPad it's still giving back a JSON string as far as I know
ReplyDeleteWho are you? I'm not aware of conflicting returned formats when using the GetProductInfo method across mobile/PC devices.
DeleteHe's a ROBLOX admin (fusroblox)
Delete