Hey guys! I'm trying to figure why doesn't this save script work. It doesnt send any error back but the value is set to false each time I rejoin/test the game
local Players = game:GetService("Players") local DataStoreService = game:GetService("DataStoreService") -- Getting data store service Players.PlayerAdded:connect(function(player) local TrackersData = DataStoreService:GetDataStore(player.UserId.."Trackers") -- Getting data store local LevelTracker = Instance.new("Folder") LevelTracker.Parent = player LevelTracker.Name = "LevelTracker" local Level1 = Instance.new("BoolValue") Level1.Parent = LevelTracker Level1.Name = "Level1" Level1.Value = false local Value = TrackersData:GetAsync("Level1") -- Getting value from data store "TrackersData" if Value == nil then TrackersData:SetAsync("Level1",false) -- if value equals nothing then it'll creates it. else Level1.Value = Value end end)
First of all you should use Pcall when you are using datastores. Problem is that you are never saving the data. Only time you set data is if player doesn't have data in the datastore. You will have to save data before player leaves or at certain interval.