Data Store not saving/loading?
Asked by
4 years ago Edited 4 years ago
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
01 | local DataStore = game:GetService( "DataStoreService" ) |
02 | local TutorialData = DataStore:GetDataStore( "CashStore" ) |
04 | game.Players.PlayerAdded:Connect( function (player) |
05 | local folder = Instance.new( "Folder" ) |
07 | folder.Parent = player |
09 | local Cash = Instance.new( "IntValue" ) |
12 | Cash.Value = TutorialData:GetAsync(player.UserId) or 500 |
13 | TutorialData:SetAsync(player.UserId, 0 ) |
15 | game.Players.PlayerRemoving:Connect( function (player) |
16 | TutorialData:SetAsync(player.UserId, Cash) |