hello! I am currently experimenting with catalog in studio, is there a way to prompt a catalog purchase on touch of a part? thanks
hello, almost surely you are looking for this:
Remember that if you want to sell products made by others you have to activate “Allow Third Party Sales”!
This Code Should Do The Work, Put Inside The Part!
local Market = game:GetService("MarketplaceService") -- Market!
--
local debounce = false -- Ony One Per Time.
local plr = nil -- The Two Functions Share This
--
local AssetID = 6311707237 -- Change With Your AssetID (This ID is From Topbar Plus)
--
function BuyPass(thing)
if game.Players:FindFirstChild(thing.Parent.Name) and debounce == false then -- Check If Player Exists
debounce = true -- Debounce
plr = game.Players:FindFirstChild(thing.Parent.Name) -- Set Player To The Player Intance, not the name
print(plr.Name.. " Touched The Part: " ..script.Parent.Name) -- Printer, Can be removed
Market:PromptPurchase(plr, AssetID) --Change this number to ID of gamepass
task.wait(1) -- Debounce
debounce = false -- Same
end
end
function PPFinished(User, BuyedAsset, isPurchased) -- Verify Status Of Player Purchase
if BuyedAsset == AssetID and User.Name == plr.Name then
if isPurchased then -- If Purchase is sucessfull do things
print("Purchase Completed. AssetID: " ..BuyedAsset.. ", Player: " ..User.Name)
else -- Same but if NOT sucessfull
warn("Purchase Canceled. AssetID: " ..BuyedAsset.. ", Player: " ..User.Name)
end
end
end
script.Parent.Touched:connect(BuyPass) -- Buy Prompt
Market.PromptPurchaseFinished:Connect(PPFinished) -- Prompt Output