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.
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
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
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.
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.
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.
proxy.Triggered:Connect(function(plr)
mps:PromptGamePassPurchase(plr, Product)
if mps:PlayerOwnsAsset(plr, Product) then
vipRoom:Destroy()
purchase:Play()
end
end)
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)