how do i make it so when you touch a part it will let you buy a gamepass and if you buy it you will get an item
local passId = 226785981 -- Replace with your game pass ID
local MarketplaceService = game:GetService("MarketplaceService")
local rep = game:GetService("ReplicatedStorage")
local function onTouched(part)
local player = game.Players:GetPlayerFromCharacter(part.Parent)
if player then
MarketplaceService:PromptGamePassPurchase(player, passId)
local hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, passId)
MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player ,passId, Purchesed)
local boombox = rep.BoomBox:Clone()
boombox.Parent = player.Backpack
end)
end
end
local part = script.Parent -- Change this to reference your part
part.Touched:Connect(onTouched)
Hello!
Try this! (Make sure Third-Party Sales are enabled under Game Settings.)
local GamepassID = 213384656 --Change this to the ID of your gamepass
local MarketplaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then -- If the part detects a humanoid then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
MarketplaceService:PromptGamePassPurchase(player,GamepassID)
local hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, GamepassID)
MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, GamepassID, Purchased)
local boombox = ReplicatedStorage:WaitForChild("Boombox")
boombox:Clone()
boombox.Parent = player.Backpack
end)
end
end
end)
If you have any questions let me know! Hope this helps!
its kind of working its giving me the item 5 times
and how do i make it so it will let you buy it once beacuse in roblox studio its letting me buy it agin @Kittylitterking123
I don’t know why it’s giving you the item multiple times, as it doesn’t do it for me. I’ll take another look at the code, though.
You shouldn’t be able to buy it again unless it’s a Developer Product. They are different from gamepasses as DevProducts you can buy multiple times such as Revives and More Coins while gamepasses you can buy only once.
To check if the player has the gamepass through code, you can use the UserOwnsGamePassAsync()
function.
MarketplaceService | Documentation - Roblox Creator Hub
but the UserOwnsGamePassAsync() doesnt work for me please and help and no im using the same id you provided
Are you getting any errors in the output?
no its not giving errors in the out put
Try this
local GamepassID = 226785981 --Change this to the ID of your gamepass
local MarketplaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local function GiveTool(player)
if player.Backpack:FindFirstChild("Boombox") then
return
end
local boombox = ReplicatedStorage:WaitForChild("Boombox")
boombox:Clone()
boombox.Parent = player.Backpack
end
script.Parent.Touched:Connect(function(hit)
if not hit.Parent:FindFirstChild("Humanoid") then -- If the part detects a humanoid then
return
end
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if not player then
return
end
local hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, GamepassID)
if hasPass then
GiveTool(player)
return
end
MarketplaceService:PromptGamePassPurchase(player, GamepassID)
MarketplaceService.PromptGamePassPurchaseFinished:Once(function(player, GamepassID, Purchased)
if not Purchased then
return
end
GiveTool(player)
end)
end)
but in studio it still leting me buy it agin
If you don’t own the game pass then it will let you test purchase it in studio try testing it in game
ok thenk you very much and i love pizza (:
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.