How do I make a value buy?

Hi, Developers!

I’ve searched everywhere in devforum and google and how do I make a Value buy?

I made a whole GUI for this. When a player buys the coin product (dev product) they get the coins

Code for the leaderboard value.

local DataStoreService = game:GetService("DataStoreService") --Calls DataStoreService



local SavedData = DataStoreService:GetDataStore("SavedData") --Gets saved data
-----------------------------------------------------------------------------------------------------------------------
game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Parent = player
	leaderstats.Name = "leaderstats"
	local coins = Instance.new("IntValue")
	coins.Name = "Coins"
	coins.Parent = leaderstats    


	local success,Data = pcall(function()
		return SavedData:GetAsync(player.UserId)
	end)
	if not Data then
		--Data = coins.Value == $0 useless junk =]
	end
	coins.Value = Data        
end)

game.Players.PlayerRemoving:Connect(function(player)
	local coins = player.leaderstats.Coins
	SavedData:SetAsync(player.UserId, coins.Value)
end)

Dev product buy code:

local productId = 1646286791 
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:connect(function() 
	game:GetService("MarketplaceService"):PromptProductPurchase(player, productId)
end)

That’s all!

do you mean to say that you want to know how to know if a player bought the dev product or not?

When someone buy a dev product, they get coins because they bought coins
image

then just check if they bought the dev product and add the coins?

script.Parent.MouseButton1Click:connect(function() 
	game:GetService("MarketplaceService"):PromptProductPurchase(player, productId)
	player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 2000
end)

if you click it just give you coins, I’m trying to make when someone buys the product they get the coins.

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