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

Why this devproduct script don't add gold to player?

Hello, I have problem with devproducts. When player buy gold it won't add him it.

Here is script:

game.StarterGui.ResetPlayerGuiOnSpawn = false

local MarketplaceService = game:GetService("MarketplaceService")

function getPlayerFromId(id)
	for i,v in pairs(game.Players:GetChildren()) do
		if v.userId == id then
			return v
		end
	end
	return nil
end
 
MarketplaceService.ProcessReceipt = function(receiptInfo)
	local productId = receiptInfo.ProductId
	local playerId = receiptInfo.PlayerId
	local player = getPlayerFromId(playerId)
	local productName 
	if productId == 32364216 then
		productName = "2,000G"
		local cashmoney = game.leaderstats.Gold:FindFirstChild(player.Name)
		if cashmoney then
			cashmoney.Value = cashmoney.Value + 2000
		end
	elseif productId == 32364229 then
		productName = "5,000G"
		local cashmoney = game.leaderstats.Gold:FindFirstChild(player.Name)
		if cashmoney then
			cashmoney.Value = cashmoney.Value + 5000
		end
	elseif productId == 32364246 then
		productName = "10,000G"
		local cashmoney = game.leaderstats.Gold:FindFirstChild(player.Name)
		if cashmoney then
			cashmoney.Value = cashmoney.Value + 10000
		end
		end
	local message = Instance.new("Hint",workspace)
	message.Text = player.Name.." purchased "..productName.."!"
	coroutine.resume(coroutine.create(function()
		wait(2)
		message:destroy()
	end))

	return Enum.ProductPurchaseDecision.PurchaseGranted		
end

I think local cashmoney is wrote wrong...

1 answer

✓ Accepted answer

Aren't leaderstats contained in the player? So you should have this:

local cashmoney = game.Players[player.Name].leaderstats.Gold -- You might be able to just have "player.leaderstats.Gold" too

1 comment

0

Okay, thank you :) Yeah i thought about it, but i wanted to ask first.

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