So with my developer products they change the value of my coins (stat) in my game but after I leave and come back they aren't saved by the other script?
Save/Load Datastore
-- Player Profile creator
local DataStore = game:GetService("DataStoreService"):GetDataStore("PlayerStats")
game.Players.PlayerAdded:connect(function(plr)
local profile = Instance.new("Folder")
profile.Parent = game.Workspace.PlayerProfiles
profile.Name = plr.Name
local profile2 = Instance.new("NumberValue")
profile2.Name = "Treasure"
profile2.Parent = profile
local profile3 = Instance.new("NumberValue")
profile3.Name = "SavedTreasure"
profile3.Parent = profile
local p22 = Instance.new("NumberValue")
p22.Name = "Coins" -- value changed by dev products
p22.Parent = profile
local p33 = Instance.new("BoolValue")
p18.Name = "TwoSeaterDinghy"
p18.Parent = profile
local p34 = Instance.new("BoolValue")
p18.Name = "SpeedDinghy"
p18.Parent = profile
--loading stats
--plr:WaitForDataReady()
wait(2)
local stats2 = game.Workspace.PlayerProfiles:FindFirstChild(plr.Name):GetChildren()
for i = 1, #stats2 do
stats2[i].Value = DataStore:GetAsync(stats2[i].Name)
print(stats2[i].Value)
end
end)
-- Profile deleter
function DeleteProfile(profile)
local Profiles = game.Workspace.PlayerProfiles
Profiles:FindFirstChild(profile):Destroy()
end
game.Players.PlayerRemoving:connect(function(plr2)
-- plr2:WaitForDataReady()
--wait(2)
local stats = game.Workspace.PlayerProfiles:FindFirstChild(plr2.Name):GetChildren()
for i=1, #stats do
print(stats[i].Name)
DataStore:SetAsync(stats[i].Name, stats[i].Value)
wait(1)
DeleteProfile(plr2.Name)
end
end)
-- Profile saver
Button Script :
--Developer Product Gui Button simplified by TehRandoms--
local devProductId = 33248065 --The Developer Product ID if your item, must be a Product of the game place it is in
local player= script.Parent.Parent.Parent.Parent.Parent
--Well, as always, don't touch anything below if you have no idea what you are doing--
--Prompt Buy--
script.Parent.MouseButton1Click:connect(function()
game:GetService("MarketplaceService"):PromptProductPurchase(player, devProductId)
end)
--Transaction--
local MarketplaceService = game:GetService("MarketplaceService")
local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
MarketplaceService.ProcessReceipt = function(receiptInfo)
for i, player in ipairs(game.Players:GetChildren()) do
if player.userId == receiptInfo.PlayerId then
if receiptInfo.ProductId == devProductId then
game.Workspace.PlayerProfiles:FindFirstChild(player.Name).Coins.Value = game.Workspace.PlayerProfiles:FindFirstChild(player.Name).Coins.Value + 50 --You can put the event here.
print(player.Name.."Bought Item "..devProductId)
end
end
end
local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_purchase_" .. receiptInfo.ProductId
ds:IncrementAsync(playerProductKey, 1)
return Enum.ProductPurchaseDecision.PurchaseGranted
end
