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 5 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:

01function onTouch(hit)
02 
03    script.Disabled=true
04 
05local   pla=game.Players:FindFirstChild(hit.Parent.Name)
06 
07    game:GetService("MarketplaceService"):PromptPurchase(pla, 666) --dont ask why 666 lol
08wait(1)
09script.Disabled=false
10end
11 
12 
13script.Parent.Touched:connect(onTouch)

Explain me what is wrong with that script

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

2 answers

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

Ok, there are a few things to address.

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

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:

1function onTouch(hit)
2    local pla = game.Players:FindFirstChild(hit.Parent.Name)
3    if pla then
4        script.Disabled = true
5        game:GetService("MarketplaceService"):PromptPurchase(pla, 666)
6        wait(1)
7        script.Disabled = false
8    end
9end

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.

01local ID = 123456789 -- Replace the numbers with the actual game pass ID
02 
03function onTouch(hit)
04    local pla = game.Players:FindFirstChild(hit.Parent.Name)
05    if pla then
06        script.Disabled = true
07        game:GetService("MarketplaceService"):PromptGamePassPurchase(pla, ID)
08        wait(1)
09        script.Disabled = false
10    end
11end
0
now it doesnt show the 'buy gamepass thing' densomenso999 11 — 5y
0
:( densomenso999 11 — 5y
0
Try using both :PromptPurchase() and PromptGamePassPurchase(). Rinpix 639 — 5y
Ad
Log in to vote
-1
Answered by 5 years ago
Edited 5 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.

01local debounce = false
02 
03local function onTouch(hit)
04    if not debounce then
05        debounce = true
06        local   player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
07 
08        game:GetService("MarketplaceService"):PromptGamePassPurchase(player, 666)
09        wait(1)
10        debounce = false
11    end
12end
13 
14script.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 — 5y
0
Disabling a script after the event listener runs won't prevent the event listener from running. Rinpix 639 — 5y
0
Then either you're doing something wrong, or it's a problem with your gamepass. youtubemasterWOW 2741 — 5y
0
hmm, i tried with a free model that is a button and put the same gamepass and it worked densomenso999 11 — 5y
0
okey what if instead of trying to do that i just add a 'buy gamepass button' lol densomenso999 11 — 5y

Answer this question