I keep trying to use data store to save variables (which is fairly new to me) . I run the game, edit the variable, and re-start the game, and the DataStore brings up a value of 0. Here is my current code. Anyone have an idea as to what's wrong? EDIT: I have API in studio on. My guess is something to do with the player removed function at the end
local DataStore = game:GetService("DataStoreService")
local TutorialData = DataStore:GetDataStore("CashStore")
game.Players.PlayerAdded:Connect(function(player)
local folder = Instance.new("Folder")
folder.Name = "stats"
folder.Parent = player
local Cash = Instance.new("IntValue")
Cash.Name = "Cash"
Cash.Parent = folder
Cash.Value = TutorialData:GetAsync(player.UserId) or 500
TutorialData:SetAsync(player.UserId, 0)
game.Players.PlayerRemoving:Connect(function(player)
TutorialData:SetAsync(player.UserId, Cash)
wait(1)
end)
end)

4 comments
line 13 you basically wipe all the data and set it to 0
Oh wow...:P thanks lol
Also , Please use 'pcall(function()' when Setting or Getting Data from DataStores. It would be dreadful to see your code error and fail during a game.
In line 13 you set the data to 0
TutorialData:SetAsync(player.UserId, 0)