a local script to prompt the gamepass in the Starter player Script
local MarketplaceService = game:GetService("MarketplaceService")
local gamePassID = 18796069
local function promptPurchase()
local player = game.Players.LocalPlayer
local hasPass = false
local sucess, message = pcall(function()
hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
end)
if hasPass then
print("Players already has the gamepass")
else
MarketplaceService:PromptGamePassPurchase(player, gamePassID)
end
end
wait(4)
promptPurchase()
A gamepass checker in the Server Script Storage
local MarketplaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Sword = ReplicatedStorage:WaitForChild("ClassicSword")
local gamePassID = 18796069
MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, purchasePassID, purchaseSucess)
if purchaseSucess == true and purchasePassID == gamePassID then
print(player.Name.. "Purchase the give sword gamepass")
Sword.Parent = player.Character
end
end)
An error gamepass remember to always give sword to the person who got the gamepass in the ServerScriptStorage
local MarketplaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Sword = ReplicatedStorage:WaitForChild("ClassicSword")
local gamePassID = 18796069
game.Players.PlayerAdded:Connect(function(player)
wait(1)
local char = game.Workspace:FindFirstChild(player.Name)
local hasPass = false
local sucess, message = pcall(function()
hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserID, gamePassID)
end)
if hasPass == true then
print("Players has the sword gamepass")
Sword.Parent = char
end
end)
And finally a ClassicSword in the ReplicatedStorage
