does anyone know how to script a prompt purchase just by stepping on a part inside an experience? Any help as soon as possible is appreciated.
Use the .Touch Event with a debounce. Like this as an example:
local db = {}
local UGCID = 0 --Change to ID of UGC
local TouchedPart = nil --Change to the pathway of the part
TouchedPart.Touched:Connect(function(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) and table.find(db, hit.Parent.Name) == nil then
table.insert(db, hit.Parent.Name)
--Prompt UGC
game:GetService("MarketplaceService"):PromptPurchase(game.Players:GetPlayerFromCharacter(hit.Parent).UserId, UGCID)
else
--Player has already Touched this part OR the object touched wasn't a Character.
end
end)
(Make sure script is a Server Script for UGCs)
Try this:
-- Script
local MarketplaceService = game:GetService("MarketplaceService")
local Part -- Insert your part here
local Id = 0 -- Insert UGC Id
local function grantUGC(hit)
if hit.Parent:FindFirstChild("Humanoid") and game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) then
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
MarketplaceService:PromptPurchase(player.UserId,Id)
end
end
Part.Touched:Connect(grantUGC)
Please make sure that you add a Debounce to it. Assuming it’s a Limited UGC you have rate limits on how much you can prompt it and you will run into issues with this quickly and fast if you don’t have a debounce.
Even if its not a Limited UGC you still have limits to PromptPurchase which you will run into quickly without running any sort of Debounce.
When player receives UGC Item, they won’t be able to get it anymore, so Debounce here makes no sense at all
Yes it will because it will be an expensive call, and the User on the other end will get your Errors. The roblox player claiming this UGC will get a prompt error of “Your purchase of [item name] failed because something went wrong. Your account has not been charged. Please try again later” If you don’t add a Debounce. Also you could be firing it so much that it causes other issues, and prevents other people within the server to claim the UGC as it adds them in the queue of hundred of requests made.
Didn’t noticed that at all, thanks for reminding and I apologize for my mistake.