I’m attempting to create a developer product that will increase the value of an IntValue inside a player’s leaderstats folder upon purchasing the product and the updated value will be backed up by a datastore. In this instance; the IntValue is named “Kills”.
Problem is that when the :GetAsync()
function is called, the value is set to zero instead of the new value that was updated for the player. (Video showcasing problem below)
Code:
Script that increases the player’s kills value after the transaction:
local MarketPlaceService = game:GetService("MarketplaceService")
MarketPlaceService.ProcessReceipt = function(receiptInfo)
print(receiptInfo)
local playerId = receiptInfo.PlayerId
local productId = receiptInfo.ProductId
if productId == 2684175514 then -- My developer product ID
local player = game.Players:GetPlayerByUserId(playerId)
player.leaderstats.Kills.Value += 50
end
end
Leaderstats script:
local DataStoreService = game:GetService("DataStoreService")
local PlayerStats = DataStoreService:GetDataStore("PlayerStats")
local PlayerKills = DataStoreService:GetDataStore("PlayerStats", "Kills")
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local kills = Instance.new("IntValue")
kills.Name = "Kills"
kills.Parent = leaderstats
while task.wait(5) do
local success, currentKills = pcall(function()
return PlayerKills:GetAsync(plr.UserId)
end)
if success then
kills.Value = currentKills
end
end
end)
Is this a Roblox problem or is it just me? (Most likely)
Any help would be appreciated, cheers!