How would I go about to add another data save to my currency "Cash"
I tried many ways but I got confused.
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local MissionsCompleted = Instance.new("IntValue")
MissionsCompleted.Name = "MissionsCompleted"
MissionsCompleted.Parent = leaderstats
local Cash = Instance.new("IntValue")
Cash.Name = "Cash"
Cash.Parent = leaderstats
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(player.UserId.."-MissionsCompleted")
end)
if success then
MissionsCompleted.Value = data
else
print("ErrorFetchingData")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
myDataStore:SetAsync(player.UserId.."-MissionsCompleted", player.leaderstats.MissionsCompleted.Value)
end)
if success then
print("DataStoreSuccess")
else
print("DataStoreError")
warn(errormessage)
end
end)
the text above is for saving the “missionscompleted” data