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()
This is the code that I would use hope it helps just make another script that is the leader board and change the value of cash other than that you can just copy and paste this. if this helps please mark it as answered.
local Cash = game.Players.LocalPlayer.leaderstats.Cash -- Don't add .Value at the end of this local Amount = 100 local passId = 15489874 local marketplaceService = game:GetService("MarketplaceService") marketplaceService.PromptPurchaseFinished:connect(function(player,assetId,isPurchased) if isPurchased then if assetId == passId then Cash.Value = Cash.Value + Amount end end end)