Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

how to Prompt Game Pass purchase on part touch?

Asked by 2 years ago

Hello, I am developing a game and there is a wall which you can only pass if you have bought a gamepass. The problem is that i tested it out with a friend but the wall was not there even tho he didnt purchase the game pass.

I've put a local script into the wall and it's

script.Parent.Touched:Connect(function(hit)
    game:GetService("MarketplaceService"):PromptGamePassPurchase(game.Players.LocalPlayer, 18801304)
end)

I've also put a script into serverscriptservice which does :

 local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local conveyorGamepassID = 18801304

game.Players.PlayerAdded:Connect(function(player)
    local success, message = pcall(function()
        hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, conveyorGamepassID)
    end)
    if hasPass then
        print("player has the gamepass")

        game.Workspace.MainBuild.MainConveyor.ConveyorBorder.CanCollide = false
    end
end)

local function onPromptGamePassPurchaseFinished(player, purchasedPassID, purchaseSuccess)
    if purchaseSuccess == true and purchasedPassID == conveyorGamepassID then
        print(player.Name .. " purchased the game pass!")

        game.Workspace.MainBuild.MainConveyor.ConveyorBorder.CanCollide = false
    end
end

MarketplaceService.PromptGamePassPurchaseFinished:Connect(onPromptGamePassPurchaseFinished)

Could anyone please help?

1 answer

Log in to vote
0
Answered by
Nozazxe 107
2 years ago
Edited 2 years ago

This is because if the player has the pass, its still a serverside, so its not for the client/player, but instead for everyone.

make a Local Script:

--PUT THIS SCRIPT UNDER STARTERGUI--

local MarketplaceService = game:GetService("MarketplaceService")
local Player = game.Players.LocalPlayer
local doorPart = game.Workspace.MainBuild.MainConveyor.ConveyorBorder
local gamepassId = 18801304

if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, gamepassId) then
    print("Player owns pass.")
    doorPart.CanCollide = false
else
    print("Player does not own pass.")
    doorPart.CanCollide = true
end
0
Nozazxe could you please help me to fix that? I'm new to scripting so i dont know that much SubNinjaPav 7 — 2y
0
Alright, here it is Nozazxe 107 — 2y
0
@SubNinjaPav Done! Nozazxe 107 — 2y
Ad

Answer this question