Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

why is the gamepass not coming after you rejoin after buying?

THIS SCRIPT IN STARTER PLAYER SCRIPTS local script

local MarketPlaceService = game:GetService("MarketplaceService")

local gamePassID = 18759963

local function promptPurchase()
	
	local player = game.Players.LocalPlayer
	local haspass = false
	
	local success, message = pcall(function()
		haspass = MarketPlaceService:UserOwnsGamePassAsync(player.UserID, gamePassID)
	end)
	
	if haspass == true then
		print("Player Aldready has the gamepass")
	else
		MarketPlaceService:PromptGamePassPurchase(player, gamePassID)
	end
end

wait(5)
promptPurchase()

this in serverscriptservice

local MarketPlaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local sword = ReplicatedStorage:WaitForChild("ClassicSword")

local gamePassID = 18759963

MarketPlaceService.PromptGamePassPurchaseFinished:Connect(function(player, purchasePassID, purchaseSuccess)
	
	if purchaseSuccess == true and purchasePassID == gamePassID then
		print(player.Name.. " purchased the sword gamepass")
		sword.Parent = player.Character
	end
	
end)

this also in server script service but in another script

local MarketPlaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local sword = ReplicatedStorage:WaitForChild("ClassicSword")

local gamePassID = 18759963


game.Players.PlayerAdded:Connect(function(player)
	wait(5)
	local char = game.Workspace:FindFirstChild(player.Name)
	local haspass = false
	
	local success, message = pcall(function()
		haspass = MarketPlaceService:UserOwnsGamePassAsync(player.UserID, gamePassID)
	end)
	
	if haspass == true then
		print("Player has sword gamepass")
		sword.Parent = char
	end
end)

2 comments

0

did it work?

0

btw, get rid of that script in start player scripts. Its useless

1 answer

So you want to check if a player has a gamepass right? Well use this script. Everytime a player joins, it checks if the player has a gamepass.

local id = YOUR_ID_HERE
 
game:GetService("MarketplaceService").PromptGamePassPurchaseFinished:Connect(function(plr,ido,purchased)
	if purchased and ido == id then
	-- your code when they have gamepass
	end
end)
 
game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:connect(function(char)
		if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(game.Players[char.Name].UserId, id) then
			--copypaste the script you wrote earlier
		end
	end)
end)

if it worked don't forget to accept it :P

This discussion is preserved as it was. New answers, comments, and votes are closed.