Gamepass Purchase

Hey guys, I need help with a GamePass script:

local mps = game:GetService("MarketplaceService")
local Product = 145084410
local vipRoom = game.Workspace.Scripts["VIP-Room"]
local proxy = vipRoom.Buy.ProximityPrompt
local purchase = game.SoundService.purchase

proxy.Triggered:Connect(function(plr)
	mps:PromptGamePassPurchase(plr, Product)
	if mps:PlayerOwnsAsset(plr, Product) then
		vipRoom:Destroy()
		purchase:Play()
	end
end)

So how should it work? When you activate the proxy, it will pop up the purchase thing, and when you click buy, it will open the room only for you, and every time you die, respawn, or rejoin, it will stay open for you only if you have the game pass.

but this is not working.

1 Like

You need to get the user id of the player, you are getting the plr object
Simply replace plr in the playerownsasset part with plr.UserId

And to check if the player owns the gamepass, just have a script in replicated first that checks if the player has the gamepass on player added

I don’t know how , I did this

local mps = game:GetService("MarketplaceService")
local Product = 145084410
local vipRoom = game.Workspace.Scripts["VIP-Room"]
local proxy = vipRoom.Buy.ProximityPrompt
local purchase = game.SoundService.purchase

proxy.Triggered:Connect(function(plr)
	mps:PromptGamePassPurchase(plr, Product)
	print("open")
end)

game.Players.PlayerAdded:Connect(function(plr)
	while true do
		wait(1)
		if mps:PlayerOwnsAsset(plr, Product) then
			print("owned")
			vipRoom:Destroy()
			purchase:Play()
		end
	end
end)

It will open the purchase popup for the player, and when the player clicks buy, it should do a loop and check if the player has the pass; if so, it will destroy, but I don’t see print("owned") in the console

only print("open")

local mps = game:GetService("MarketplaceService")
local Product = 145084410
local vipRoom = game.Workspace.Scripts["VIP-Room"]
local proxy = vipRoom.Buy.ProximityPrompt
local purchase = game.SoundService.purchase

proxy.Triggered:Connect(function(plr)
	mps:PromptGamePassPurchase(plr.UserId, Product)
	if mps:PlayerOwnsAsset(plr.UserId, Product) then
		vipRoom:Destroy()
		purchase:Play()
	end
end)
local mps = game:GetService("MarketplaceService")
local Product = 145084410
local vipRoom = game.Workspace.Scripts["VIP-Room"]
local proxy = vipRoom.Buy.ProximityPrompt
local purchase = game.SoundService.purchase

proxy.Triggered:Connect(function(plr)
	mps:PromptGamePassPurchase(plr.UserId, Product)
	print("open")
end)

game.Players.PlayerAdded:Connect(function(plr)
	while true do
		wait(1)
		if mps:PlayerOwnsAsset(plr.UserId, Product) then
			print("owned")
			vipRoom:Destroy()
			purchase:Play()
		end
	end
end)

you have such a script written a little strangely

I can suggest a slightly different script for you

Alternative

--Script
local vipRoom = game.Workspace.Scripts["VIP-Room"]
local proxy = vipRoom.Buy.ProximityPrompt
local purchase = game.SoundService.purchase

local Product = 145084410

proxy.TriggerEnded:Connect(function(player)
if mps:PlayerOwnsAsset(player.UserId, Product) then
        vipRoom:Destroy()
		purchase:Play()
else
            	mps:PromptProductPurchase(player.UserId,Product)
      end
end)

--Server script
local MPS = game:GetService("MarketplaceService")

local productFunctions = {
	[1] = function(player) -- [ID] 
	   --Function 
	end,
	[2] = function(player) 
		--
	end,
	[3] = function(player)
		--
	end,
	[4] = function(player)
		--
	end,
	[5] = function(player)
		--
	end,
	[6] = function(player)
		--
	end,
}


MPS.ProcessReceipt = function(receiptInfo)
	local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId) 

	if not player then
		warn("Purchase error")
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end

	local success = pcall(productFunctions[receiptInfo.ProductId], player)

	if not success then
		warn("Purchase error")
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end

	return Enum.ProductPurchaseDecision.PurchaseGranted
end

Doesn’t Work!1!1!1!1!1!1!1!1!1

Here’s a modified version of the code that should work as you described:

local mps = game:GetService("MarketplaceService")
local Product = 145084410
local vipRoom = game.Workspace.Scripts["VIP-Room"]
local proxy = vipRoom.Buy.ProximityPrompt
local purchase = game.SoundService.purchase

-- Function to check if the player owns the game pass
local function ownsGamePass(player)
    local success, message, info = pcall(function()
        return mps:PlayerOwnsAsset(player, Product)
    end)
    if success then
        return info
    else
        print("Error checking game pass ownership:", message)
        return false
    end
end

-- Function to handle player spawned event
local function onPlayerSpawned(player)
    local character = player.Character
    if character then
        local vipRoomClone = vipRoom:Clone()
        vipRoomClone.Parent = character
        vipRoomClone:SetPrimaryPartCFrame(character.HumanoidRootPart.CFrame)
        if not ownsGamePass(player) then
            vipRoomClone:Destroy()
        end
    end
end

-- Connect the onPlayerSpawned function to the PlayerAdded event
game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        onPlayerSpawned(player)
    end)
    if player.Character then
        onPlayerSpawned(player)
    end
end)

proxy.Triggered:Connect(function(player)
    if ownsGamePass(player) then
        local vipRoomClone = vipRoom:Clone()
        vipRoomClone.Parent = player.Character
        vipRoomClone:SetPrimaryPartCFrame(player.Character.HumanoidRootPart.CFrame)
        purchase:Play()
    else
        mps:PromptGamePassPurchase(player, Product)
    end
end)

This code first defines a function ownsGamePass to check if a player owns the game pass. It then defines a function onPlayerSpawned to handle the player spawned event. This function clones the VIP room and parents it to the player’s character, but only if the player owns the game pass. Finally, it connects the Triggered event of the ProximityPrompt to a function that checks if the player owns the game pass. If they do, it clones the VIP room and parents it to the player’s character. If not, it prompts the player to purchase the game pass.

what do I need with the clone thing?

Error:
SetPrimaryPartCFrame is not a valid member of Part "Koki0991.VIP-Room"

The VIP Room is an invisible part I want, and when the player purchases it, it will destroy the part for the player who owns the pass, so he is the only one who can enter the room.

Is VIP-Room a model… ?

sdchrr

If its a part, then just destroy the part on the client using a remote event

not a model It’s a regular part that’s invisible, so players can’t enter unless the part is destroyed.

The script you wrote prompts the gamepass purchase event… and then checks if the player owns the asset? [You have to trigger it twice] – maybe?.. also you have to destroy it on the client, not the server, if you don’t want anyone else except the player to have access to the room… You can do this using a remote event.

@Koki0991 the

proxy.Triggered:Connect(function(plr)
	mps:PromptGamePassPurchase(plr, Product)
	if mps:PlayerOwnsAsset(plr, Product) then
		vipRoom:Destroy()
		purchase:Play()
	end
end)

local script or just script?

The Script I wrote is a server script!

Did you use the advice I gave? Did it work?

In my opinion this is a bad idea from the game protection side (Although you can’t do otherwise here)

Yes I did but i get error because cloning thing and i don’t want clone only destroy

Remove the cloning part… only destroy…

im guessing you are following his script??

no, I used Your Script 1 1 1 1 1 1 1 1

I didn’t even make a script… you are just using your own script now

oh nvm it wasn’t you gave me a script

ok What do I do now I made this

Server Script:

local mps = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local VIPEvent = ReplicatedStorage.Events.VIPEvent

local Product = 145084410

VIPEvent.OnServerEvent:Connect(function(player)
	mps:PlayerOwnsAsset(player, Product)
end)

Local Script:

local vipRoom = game.Workspace.Scripts["VIP-Room"]
local proxy = vipRoom.Buy.ProximityPrompt
local purchaseSound = game.SoundService.purchase
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local VIPEvent = ReplicatedStorage.Events.VIPEvent

proxy.Triggered:Connect(function()
	VIPEvent:FireServer()
	purchaseSound:Play()
end)