So when I try to purchase something from my currency shop the data wont save. It only saves for the Coins but not strength or water. Is there any possible solutions to this?
local DataStore = game:GetService("DataStoreService"):GetDataStore("DataStore")
local MPS = game:GetService("MarketplaceService")
-- leaderstats --
game.Players.PlayerAdded:Connect(function(Player)
local Leaderstats = Instance.new("Folder")
Leaderstats.Name = "leaderstats"
Leaderstats.Parent = Player
local Coins = Instance.new("NumberValue")
Coins.Name = "Coins"
Coins.Parent = Leaderstats
local Strength = Instance.new("NumberValue")
Strength.Name = "Strength"
Strength.Parent = Leaderstats
local Rebirths = Instance.new("NumberValue")
Rebirths.Name = "Water"
Rebirths.Parent = Leaderstats
local CoinsData
local StrengthData
local RebirthsData
local Success, ErrorMessage = pcall(function()
CoinsData = DataStore:GetAsync(Player.UserId.."-CashData")
StrengthData = DataStore:GetAsync(Player.UserId.."-PointsData")
RebirthsData = DataStore:GetAsync(Player.UserId.."-RebirthsData")
end)
if not Success then
print(ErrorMessage)
end
if CoinsData ~= nil then
Coins.Value = CoinsData
else
Coins.Value = 0
end
if StrengthData ~= nil then
Strength.Value = StrengthData
else
Strength.Value = 0
end
if RebirthsData ~= nil then
Strength.Value = RebirthsData
else
Strength.Value = 0
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
pcall(function()
DataStore:SetAsync(Player.UserId.."-CashData", Player.leaderstats.Coins.Value)
DataStore:SetAsync(Player.UserId.."-PointsData", Player.leaderstats.Strength.Value)
DataStore:SetAsync(Player.UserId.."-RebirthsData", Player.leaderstats.Rebirths.Value)
end)
end)```