Game Prompting Everyone In My Game To Buy Gamepass When Someone Touches Part

I Have A Gamepass In My Game But When Someone Touches The Part To Purchase The Gamepass The Server Prompts Everybody In The Game To Purchase The Gamepass But When The Users Click the “Cancel” Button The Game Gives The Users The Item Just Like They Clicked The Purchase Button Here Is My Script:

local player = game.Players.LocalPlayer
local gamepassid = 50179266
local door = game.Workspace.VIPRoom.VIPMessage
local mps = game:GetService('MarketplaceService')

local function gamepass(...)
	game:GetService('MarketplaceService'):UserOwnsGamePassAsync(player.UserId, gamepassid)
	door.CanCollide = false
	print('Prompt Gamepass Finished', ...)
end

local button = game.Workspace.VIPRoomPurchase

local function purchase(...)
	if button.Touched then
		if mps:UserOwnsGamePassAsync(player.UserId, gamepassid) == true then
			print('User Already Owns GamePass!')
		else
		local mps = game:GetService('MarketplaceService')
		mps:PromptGamePassPurchase(player, gamepassid)
		mps.PromptGamePassPurchaseFinished:Connect(gamepass)
	
		end
	end
end

button.Touched:Connect(purchase)

Thanks, Sorry If This Is Confusing.

Instead of checking for the local player’s ID, since you have made it a variable, check for the player that has touched the button. This will solve the global prompt issue.

You will then need to check if the player has actually purchased the gamepass.
The PromptGamePassPurchaseFinished will run everytime the prompt goes away anyway.
Read this and you will understand what to do.
https://developer.roblox.com/en-us/api-reference/event/MarketplaceService/PromptGamePassPurchaseFinished
Hope it helps you, ask me any questions. Good luck.

1 Like