Gamepass prompt not working


local part = workspace.Part – Change YourPartName to your part which players have to click.
local MarketPlaceService = game:GetService(“MarketplaceService”)
local GamepassID = 13600173502 – Change this ID to your Badge ID

part.Touched:Connect(function(player)
MarketPlaceService:PromptGamePassPurchase(player, GamepassID)
end)

2 Likes

When you say part.Touched:Connect(function(player), it indicates that it will prompt the gamepass to the “player” that touched. However, the part is not touched by a player but rather a part of the player.

To correct this, you should use:

local part = workspace.Part -– Change YourPartName to your part which players have to click.
local MarketPlaceService = game:GetService(“MarketplaceService”)
local GamepassID = 13600173502 –- Change this ID to your Badge ID
local touched = false


part.Touched:Connect(function(hit)
	if touched == false then
		local char = hit.Parent
		local player = game.Players:GetPlayerFromCharacter(char)
		
		if player then
			MarketPlaceService:PromptGamePassPurchase(player, GamepassID)
			touched = true
			wait(5)
			touched = false
		end
	end
end)
2 Likes

The part is not in the script, the script is in SSS

2 Likes

In the script you provided it has

local part = workspace.Part

So, it’s a part inside the workspace.

2 Likes

Yes, the script is not in the part though

2 Likes

Yes, I understand.

In my first message, I might have confusion you by saying, “If this script is within a part.” Since you already have a variable named part, you can utilize the code I provided above to resolve your issue.

2 Likes

so whats different is you have defined the char and player?

2 Likes

Basically yes. In your code you have the argument player when it’s not actually the player but a part of the player [e.g. leg]. So by defining the character you’ll be sure that the gamepass is prompted to a player.

1 Like

ah yes it works many thanks :smiley:

2 Likes

I know the reason. You need to put game.Players.PlayerAdded:Connect(function(Player) first (on the first line) in the script (move it into your part). Then, make the same, but script.Parent.Touched:Connect(function(Touched), and after that all you need to put local HumanoidRootPart = Touched.Parent:WaitForChild(“HumanoidRootPart”), then, after it, write if HumanoidRootPart then run the purchase script.

NOTE: .Touched function doesn’t created to use MarketPlace service with it.

1 Like

But after it identified you as player, add script.Parent.CanTouch = false and after the MarketPlace purchase request (wait every 5 seconds or more), set it to true, because it will send inf requests on the script and purchase requests.

1 Like

Give me an second, I’ll try it.

1 Like

Try this one (create script in the part):

local ID = 720226294

game.Players.PlayerAdded:Connect(function(Player)
	script.Parent.Touched:Connect(function(Touched)
		local HumanoidRootPart = Touched.Parent:WaitForChild("HumanoidRootPart")
		if HumanoidRootPart then
			script.Parent.CanTouch = false
			game:GetService("MarketplaceService"):PromptGamePassPurchase(Player, ID)
			wait(5)
			script.Parent.CanTouch = true
		end
	end)
end)

Change the ID to your one.

1 Like

It’s really stupidly. It will send inf purchase requests and will spam warn messages in the console. You can set CanTouch for the part to false, and turn it on after some couple of seconds.

1 Like

I agree with the spam of the request. I was my bad for not mentioning it.

This should fix the problem:

local part = game.Workspace.Part 
local MarketPlaceService = game:GetService("MarketplaceService")
local GamepassID = 13600173502 
local touched = false


part.Touched:Connect(function(hit)
	if touched == false then
		local char = hit.Parent
		local player = game.Players:GetPlayerFromCharacter(char)
		
		if player then
			MarketPlaceService:PromptGamePassPurchase(player, GamepassID)
			touched = true
			wait(5)
			touched = false
		end
	end
end)

As for the errors, if you have copied the code, the variables had one - instead of 2 so it wasn’t a comment.

1 Like

Thanks for fixing it. But, will the changeable local thing will fix the spam problem? I think that it just done the script and will continue spamming.

In Line 8 I’ve placed if touched == false then so it checks if the touched is false or true.

In lines 14-16 I’ve placed:

touched = true
wait(5)
touched = false

which will make touch true, so it cannot proccess the prompt function and after 5 seconds it will make it false to when the part it touched again it will prompt it.

This is preventing the spam.