Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I make it read data? It sends no errors back

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)

2 comments

0

you can only save one value when saving data to a datastore, so put all your values in a table

0

like?

1 answer

✓ Accepted answer

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.

3 comments

0

prints 1-12

0

Then there is no error in that script.

0

Look at any other scripts you have that are linked to it to find out where the error is coming from.

This discussion is preserved as it was. New answers, comments, and votes are closed.