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)
Thanks to everyone :) this was answered by @greatneil80 and a tip by @Tizzel40 Thanks to you two!