Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-5

I thought this script works but.... it doesn't?

Asked by 10 years ago

I bought it and I wasn't awarded a point. I don't know what's wrong.

GUI Script: local productId = 20752460
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:connect(function() --DONT CHANGE THIS Game:GetService("MarketplaceService"):PromptProductPurchase(player, productId) end)

Leaderboard Script: game.Players.ChildAdded:connect(onPlayerEntered)

function onPlayerEntered(newPlayer) local stats = Instance.new("IntValue") stats.Name = "leaderstats"

local cash = Instance.new("IntValue")
cash.Name = "Immunity"
cash.Value = 0 

cash.Parent = stats
stats.Parent = newPlayer

end

game.Players.ChildAdded:connect(onPlayerEntered)

StatDataPersistence: function saveScore(player, score) player:SaveNumber("Immunity", score) -- rename "Ingredients" with your currency/statistic name... end

function loadScore(player, clickCounter)

local score = player:LoadNumber("Immunity") -- rename "Ingredients" with your currency/statistic name...

if score ~= 0 then
    clickCounter.Value = score
else
    print("Nothing to load/score was 0")
end

end

function onPlayerEntered(newPlayer) wait() local clicks = Instance.new("IntValue") clicks.Name = "Immunity" clicks.Value = 0

    local leaderstats = Instance.new("IntValue")
    leaderstats.Name = "leaderstats"

    leaderstats.Parent = newPlayer
    clicks.Parent = leaderstats

    newPlayer:WaitForDataReady()

    loadScore(newPlayer, clicks)

end

function onPlayerRemoving(player) print("Attempting to save score for " .. player.Name) local clicks = player:FindFirstChild("leaderstats"):FindFirstChild("Immunity") if (clicks ~= nil) then saveScore(player, clicks.Value) end end

game.Players.PlayerAdded:connect(onPlayerEntered) game.Players.PlayerRemoving:connect(onPlayerRemoving)

0
Please put all you code in a code block. Perci1 4988 — 10y

1 answer

Log in to vote
0
Answered by
noliCAIKS 210 Moderation Voter
10 years ago

For the purchase to work, you need to create a Script in Workspace or ServerScriptService with the following code in it:

local ImmunityId = 20752460

Game:GetService("MarketplaceService").ProcessReceipt = function(receiptInfo) 
    for _, player in ipairs(game.Players:GetPlayers()) do
        if player.userId == receiptInfo.PlayerId then
           if receiptInfo.ProductId == ImmunityId then
                player.leaderstats.Immunity.Value = player.leaderstats.Immunity.Value + 1
                return Enum.ProductPurchaseDecision.PurchaseGranted
            end
        end 
    end
end
Ad

Answer this question