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

Why doesnt this work properly? [closed]

Asked by 9 years ago

This question already has an answer here:

Why wont this dev product work?

I am trying to make it so that once the player buys this product he will be rewarded with 50 credits. For some reason its not working.

Cash = script.Parent.Parent.Parent.Parent.Parent:WaitForChild("leaderstats"):WaitForChild("Credits")
-- setup local variables
local MarketplaceService = Game:GetService("MarketplaceService")
local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
local productId = 20768659

-- define function that will be called when purchase finished
MarketplaceService.ProcessReceipt = function(receiptInfo) 

    -- find the player based on the PlayerId in receiptInfo
    for i, player in ipairs(game.Players:GetChildren()) do
        if player.userId == receiptInfo.PlayerId then

            -- check which product was purchased
            if receiptInfo.ProductId == productId then
                --handle purchase. In this case we are highering the player's WalkSpeed         
                function onClick()
                    if Cash.Value >= 0 then
                        Cash.Value = Cash.Value + 100
                -- more feedback for the player.
                game.Workspace.DisplayScreen.SurfaceGui.TextBox.Text = player.Name .. " has purchased a healing potion."
                    end
                end
            end
        end
    end 
end

0
Your onClick function has not been connected and is never manual called. GoldenPhysics 474 — 9y

Marked as Duplicate by M39a9am3R, TheeDeathCaster, and Shawnyg

This question has been asked before, and already has an answer. If those answers do not fully address your question, then please ask a new question here.

Why was this question closed?

1 answer

Log in to vote
0
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
9 years ago

Sir, there is a unwritten rule of not posting duplicate questions, I am assuming it goes under the category of spam which is a violation of the rules really without saying. But your question was already posted and is still on the front page. Please refrain from reposting your question, and allow time for your previous one to be answered, thank you.

Ad