How do I give a gamepass instantly?

I have looked but couldn’t find a solution. I have a gamepass that gives the player a tool. It works but you have to rejoin for the gamepass to give you the tool. I want to code a script that gives the player the tool instantly instead of having to rejoin. This is my code:

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local gamePassID = 0

function Spawned(player)

	local HasGamepass = false

	local success, message = pcall(function()
		HasGamepass = MarketplaceService:UserOwnsGamePassAsync(player.userId, gamePassID)
	end)

	if not success then
	
		return
	end

	if HasGamepass == true then
		game.ServerStorage.ClassicSword:Clone().Parent = player.Backpack
	end 
end

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function()
		Spawned(player)
	end)
end)

Players.PlayerSpawned:Connect(Spawned)

MarketplaceService.PromptGamePassPurchaseFinished MarketplaceService | Documentation - Roblox Creator Hub

2 Likes
game.MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, gamepassId, wasPurchased)
	if wasPurchased and gamePassId == swordPassId then
		-- give player the sword
	end
end)

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