Im trying to make a game pass that gives a bunch of cash when bought however I don't know how to properly access the leader stats to add more cash. ** This is my Code for the server script part of the game pass**
local RS = game:GetService("ReplicatedStorage")
local sword = RS:WaitForChild("Sword")
local currencyName = "Cash"
local gamePass = game:GetService("MarketplaceService")
gamePassId = 15489874
gamePass.PromptGamePassPurchaseFinished:Connect(function(player, passId, purchaseSuccess)
if purchaseSuccess and passId == gamePassId then
local player = game.Players:GetPlayers()
local stats = player:FindFirstChild("leaderstats")
stats[currencyName].Value = stats[currencyName].Cash.Value + 34567
print(" purchases was successful")
end
end)
**This is my code for the local script **
local gamePass = game:GetService("MarketplaceService")
gamePassId = 15489874
local function Pass ()
local player = game.Players.LocalPlayer
local check = false
local success, error = pcall(function()
check = gamePass:UserOwnsGamePassAsync(player.UserId, gamePassId)
end)
if check then
gamePass:PromptGamePassPurchase(player, gamePassId)
print("Pass owned")
else
gamePass:PromptGamePassPurchase(player, gamePassId)
print("Getting pass")
end
end
wait(5)
Pass()

3 comments
have you tried using remote functions?
'GetPlayers' will return a collection of the Player Objects under the 'Players' container. Since it is an array, you're going to get a conflict on line 10. You need the individual Player Instance, which is fortunately provided by 'PromptGamePassPurchaseFinished' when executing your callback. You've already allocated the parameter, simply use it.
Another thing you should keep in mind is that GamePasses are one-time purchases. When buying in-game currency, this isn't ideal. You're going to want to look into Developer Products, as they will allow perpetual purchases.