I know if it sounds stupid, but I have no idea why my datastore is not working. The first one works, to check if the user has been there, but the second one to save the cash is not working any ideas?
Player = game:GetService("Players")
local DataStore = game:GetService("DataStoreService")
local PlayerData = DataStore:GetDataStore("PlayerData")
local PlayerCash = DataStore:GetDataStore("PlayerCash")
Player.PlayerAdded:connect(function(Player)
local stat = Instance.new("IntValue", Player)
stat.Name = "leaderstats"
local Cash = Instance.new("IntValue", stat)
Cash.Name = "Cash"
local Old = PlayerData:GetAsync(Player.UserId)
local OldCash = PlayerCash:GetAsync(Player.UserId)
if OldCash then
Cash.Value = PlayerCash:SetAsync(Player.UserId, Cash.Value)
else
PlayerCash:SetAsync(Player.UserId, Cash.Value)
end
if Old then
print("The player has been here!")
else
print("Player hasn't been here!")
PlayerData:SetAsync(Player.UserId, true)
end
end)
Player.PlayerRemoving:connect(function(Player)
print("Saving Data!")
PlayerCash:SetAsync(Player.UserId, Player.leaderstats.Cash.Value)
end)
