Help with DataStoring a number and showing it

Main goal of this topic is to know how many players bought a devproduct in my game, and make it visible to everyone

So i have a DevProduct and a counter part.

i want to make it so once any player buys a devproduct, it’ll increase ProductData numbervalue inside the counter.
image

The ShowNumber textlabel should show current value of my ProductData number. So i just need a script to store ProductData value, and increase it by +1 everytime a player buys devproduct, then everytime a new server creates it should load in the stored number and keep increasing it after someone buys product.

3 Likes

I kinda find this a “must have” when everyone can look how much got invested
inside a game. But Idk how to do a DevPro. Counter.

I try making one but don’t hope for the best, If I get nothing.

But great idea!

I got something working, but in the wrong way I’ll explain the parts:

ScreenGui Localscript

local MarketplaceService = game:GetService("MarketplaceService")
local ProductId = 1234567890 -- Change this ID with your Developer Product ID

script.Parent.MouseButton1Click:Connect(function()
	MarketplaceService:PromptProductPurchase(game.Players.LocalPlayer, ProductId)
end)

Counter Script

local DeveloperProductID = 1234567890 -- Change this ID with your Developer Product ID
local Data = game.Workspace.Counter.ProductData -- Depending if you change the name of the part, you need to change the "ProductDoor" to your part name.

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local Purchased = false

		game:GetService("MarketplaceService").ProcessReceipt = function(receiptInfo)
			if receiptInfo.ProductId == DeveloperProductID and not Purchased then
				
				Data.Value = Data.Value + 1
				
			end
		end
	end)
end) 

So the first LocalScript works perfectly, nothing to add.

Now the second Normal Script:
It is inside the Counter (Part)
and checks if player got a DevProduct after buying one and adds one to your ProductData.

Here comes the problem:
If someone is buying it more than one time in one sitting, the number adds by another one so
the player has bought 2 DevProducts and the if sentences checks how many times it should go through. The ProductData.Value goes up to 3.

I have literally no idea maybe someone else might help with the MarketplaceService.

thanks, after a while i found the answer by myself - finally studied datastores and everything went well. but thanks for the reply, i’ll mark it as a solution!

1 Like

Well it wasn’t actually DataStorage but I am proud that
I could gave you some ideas!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.