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

How to pop up a gamepass when someone touch a brick?

Asked by 4 years ago

okey so i want to make something like 'touch here to buy game pass' and i search pop up gamepass script or brick and i found a script, but when i touch the brick it says the item is not currently available.

the script:

function onTouch(hit)

    script.Disabled=true

local   pla=game.Players:FindFirstChild(hit.Parent.Name)

    game:GetService("MarketplaceService"):PromptPurchase(pla, 666) --dont ask why 666 lol
wait(1)
script.Disabled=false
end


script.Parent.Touched:connect(onTouch)

Explain me what is wrong with that script

0
why are you disabling the script? p0vd 207 — 4y
0
waiut let me change that and answer your question densomenso999 11 — 4y

2 answers

Log in to vote
0
Answered by
Rinpix 639 Moderation Voter
4 years ago
Edited 4 years ago

Ok, there are a few things to address.

function onTouch(hit)
    script.Disabled = true
    local pla = game.Players:FindFirstChild(hit.Parent.Name)
    game:GetService("MarketplaceService"):PromptPurchase(pla, 666)
    wait(1)
    script.Disabled = false
end

Disabling the script after the event listener starts running won't actually prevent the event listener from running, as the others have suggested. The script still runs because it's an event listener; if the event occurs, a separate thread of code is created and runs regardless of the state of the Disabled property of the parent script.

For anyone who is tempted to contest that, I tested this and it's true.

Okay, now that that's out of the way, the pla variable isn't always going to be returning a player. It's entirely possible that a part that isn't from a player touches it.

Ensure that a player is touching the part:

function onTouch(hit)
    local pla = game.Players:FindFirstChild(hit.Parent.Name)
    if pla then
        script.Disabled = true
        game:GetService("MarketplaceService"):PromptPurchase(pla, 666)
        wait(1)
        script.Disabled = false
    end
end

As you can see, I adjusted the code so that it only disables the script when a player touches the part. Whenever the part is touched, it checks to see if a player touched the part, and if a player did touch the part, then prompt the purchase.

But another problem here is that you need to use :PromptGamePassPurchase() and not :PromptPurchase().

I don't know if the two functions can be used interchangeably in the context of purchasing a game pass, but it's probably safer because there's a function that is delegated to the purchase of a game pass.

You also need to replace the 666 with the actual ID of your game pass, which can be found in the URL of the game pass. The script needs to know which particular game pass to prompt the player to purchase.

I know it's possible he put that there to conceal the game pass ID, but I'm just being safe.

local ID = 123456789 -- Replace the numbers with the actual game pass ID

function onTouch(hit)
    local pla = game.Players:FindFirstChild(hit.Parent.Name)
    if pla then
        script.Disabled = true
        game:GetService("MarketplaceService"):PromptGamePassPurchase(pla, ID)
        wait(1)
        script.Disabled = false
    end
end
0
now it doesnt show the 'buy gamepass thing' densomenso999 11 — 4y
0
:( densomenso999 11 — 4y
0
Try using both :PromptPurchase() and PromptGamePassPurchase(). Rinpix 639 — 4y
Ad
Log in to vote
-1
Answered by 4 years ago
Edited 4 years ago

You made it so that the script gets disabled when an instance hits the part, which means that the script will get disabled and not run the code inside it. Maybe you were trying to make a cooldown/debounce? Also, I'd use :GetPlayerFromCharacter() since it's a built-in function. The code below includes the cooldown/debounce.

local debounce = false

local function onTouch(hit)
    if not debounce then
        debounce = true
        local   player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)

        game:GetService("MarketplaceService"):PromptGamePassPurchase(player, 666) 
        wait(1)
        debounce = false
    end
end

script.Parent.Touched:Connect(onTouch)

Also, it probably says the item isn't available because it's off sale. Try using a gamepass that isn't off sale.

0
it keeps saying the same, and my pass is on sale densomenso999 11 — 4y
0
Disabling a script after the event listener runs won't prevent the event listener from running. Rinpix 639 — 4y
0
Then either you're doing something wrong, or it's a problem with your gamepass. youtubemasterWOW 2741 — 4y
0
hmm, i tried with a free model that is a button and put the same gamepass and it worked densomenso999 11 — 4y
0
okey what if instead of trying to do that i just add a 'buy gamepass button' lol densomenso999 11 — 4y

Answer this question