Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Drakyd 1
4 years ago

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)
0
you can only save one value when saving data to a datastore, so put all your values in a table joshxie 25 — 4y
0
like? Drakyd 1 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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.

0
prints 1-12 Drakyd 1 — 4y
0
Then there is no error in that script. Just2Terrify 566 — 4y
0
Look at any other scripts you have that are linked to it to find out where the error is coming from. Just2Terrify 566 — 4y
Ad

Answer this question