Hello! I was just coming by to ask about gamepasses and subplaces
See, What I want to achieve here. Is if you buy a gamepass off of a roblox store, Once that exact gamepass is bought it’ll allow you to teleport to the subplace, But if you don’t own it you will be prompted to buy it before continuing
If anything, Could I have help with that please? Thanks!
put this script in the part that contains the click detector
local TeleportService = game:GetService("TeleportService")
local MarketplaceService = game:GetService("MarketplaceService")
local Part = script.Parent
local ClickDetector = Part:FindFirstChild("ClickDetector")
local GamepassID = 0
local SubplaceID = 0
ClickDetector.MouseClick:Connect(function(playerClick)
local CheckGamepass = MarketplaceService:UserOwnsGamePassAsync(playerClick.UserId, GamepassID)
if CheckGamepass then
TeleportService:TeleportAsync(SubplaceID, playerClick)
else
MarketplaceService:PromptGamePassPurchase(playerClick, GamepassID)
end
end)
When a player wants to teleport to the subplace, send a remoteEvent to the server.
The server will check if the player owns the right assets (gamepass in this case), if they do then they get sent to the subplace, if not it prompts the user to buy the gamepass.
If you want, you can also hook a promptgamepasspurchased event to attach a listener so that when the player buys the gamepass, it immediately teleports them to the place without having them to click the button again (or whatever they do to teleport).
local TeleportService = game:GetService("TeleportService")
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local GamepassID = 0
local SubplaceID = 0
local teleportButton = playerGui:WaitForChild("ScreenGui"):WaitForChild("TeleportButton")
teleportButton.MouseButton1Click:Connect(function()
local success, ownsGamepass = pcall(function()
return MarketplaceService:UserOwnsGamePassAsync(player.UserId, GamepassID)
end)
if success and ownsGamepass then
TeleportService:TeleportAsync(SubplaceID, player)
elseif success then
MarketplaceService:PromptGamePassPurchase(player, GamepassID)
end
end)