Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

how to Prompt Game Pass purchase on part touch?

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

✓ Accepted answer

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

3 comments

0

Nozazxe could you please help me to fix that? I'm new to scripting so i dont know that much

0

Alright, here it is

0

@SubNinjaPav Done!

This discussion is preserved as it was. New answers, comments, and votes are closed.