Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

1 answer

✓ Accepted answer

plr.leaderstats.Points.Value = plr.leaderstats.Points.Value + 50

Edit Points to whatever Credits is called on the leaderboard and then make it so when they purchase the product, it runs that code. I am not an expert, so you gotta figure the rest out, sorry :(, but I can help you with some things.

Also don't double post...

This discussion is preserved as it was. New answers, comments, and votes are closed.