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!