Gamepass Purchase

Final Script:

Server Script:

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

local Product = 145084410

proxy.Triggered:Connect(function(plr)
	if mps:PlayerOwnsAsset(plr,Product) then
		VIPEvent:FireClient()
	else
		mps:PromptGamePassPurchase(plr,Product)
	end
end)

mps.PromptGamePassPurchaseFinished:Connect(function(player, pass_id, was_purchased)
	if Product == pass_id and was_purchased then
		VIPEvent:FireClient(player)
	end
end)

Local Script:

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

VIPEvent.OnClientEvent:Connect(function(plr)
	vipRoom:Destroy()
	purchaseSound:Play()
end)
1 Like

I have a question. Will it be opened automatically when the player who owns the game pass dies or joins/re-joins the game?

or you need to click the proxy every time

You need to click the proxy every time. How ever still this can be done in ServerScript in script service by using what you made previously. When the player dies, nothing happens. It will always be open

game.Players.PlayerAdded:Connect(function(plr)
		if mps:PlayerOwnsAsset(plr, Product) then
			VIProom:FireClient(plr)
		end
end)
1 Like

Thank you this is the script:

Server Script:

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

local Product = 145084410

proxy.Triggered:Connect(function(plr)
	if mps:PlayerOwnsAsset(plr,Product) then
		VIPEvent:FireClient()
	else
		mps:PromptGamePassPurchase(plr,Product)
	end
end)

mps.PromptGamePassPurchaseFinished:Connect(function(player, pass_id, was_purchased)
	if Product == pass_id and was_purchased then
		VIPEvent:FireClient(player)
	end
end)

game.Players.PlayerAdded:Connect(function(plr)
	if mps:PlayerOwnsAsset(plr, Product) then
		VIPEvent:FireClient(plr)
	end
end)

Local Script:

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

VIPEvent.OnClientEvent:Connect(function(plr)
	vipRoom:Destroy()
	purchaseSound:Play()
end)

Nice but I might say that this part should be done in ServerScript inside of ScriptService so that the client can’t access this part.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.