Whenever i give myself cash it's suppose to save but it won't
`local currencyName = "Cash"
local DataStore = game:GetService("DataStoreService"):GetDataStore("TestDataStore")
game.Players.PlayerAdded:Connect(function(player)
local folder = Instance.new("Folder")
folder.Name = "leaderstats"
folder.Parent = player
local currency = Instance.new("IntValue")
currency.Name = currencyName
currency.Parent = folder
local ID = currencyName.."-"..player.UserId
local savedData = nil
pcall(function()
local savedData = DataStore:GetAsync(ID)
end)
if savedData ~= nil then
currency.Value = savedData
print("Data loaded")
else
currency.Value = 100
print("Players to the game")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local ID = currencyName.."-"..player.UserId
DataStore:SetAsync(ID,player.leaderstats[currencyName].Value)
end)
game:BindToClose(function()
for i,player in pairs(game.Players:GetPlayers()) do
if player then
player:Kick("This game is shutting down ok.")
end
end
wait(5)
end)`

5 comments
Is this in Roblox Studio?
Are you giving you'reself cash through a code else it wont save beacuse you did it from the clients side and beacuse of fe it will think it is a exploit doing it. But i may be wrong
Check this out: https://developer.roblox.com/articles/Saving-Player-Data
You should probably put this in a ModuleScript too inside of ServerStorage.
0k