Hey guys! I tried to make this script read data using GetAsync, but I can't get it to work properly. Could someone please help?
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)
to see where something isn't working to, use the code below.
print(1)
Up the number on each line you do. Here's what I'd suggest doing.
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 print(1) local LevelTracker = Instance.new("Folder") print(2) LevelTracker.Parent = player print(3) LevelTracker.Name = "LevelTracker" print(4) local Level1 = Instance.new("BoolValue") print(5) Level1.Parent = LevelTracker print(6) Level1.Name = "Level1" print(7) Level1.Value = false print(8) local Value = TrackersData:GetAsync("Level1") -- Getting value from data store "TrackersData" print(9) if Value == nil then print(10) TrackersData:SetAsync("Level1",false) -- if value equals nothing then it'll creates it. print(11) else Level1.Value = Value print(12) end end)
Which ever print doesn't print out in output, will be the line that's screwing up.