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

DataStores not updating, any help?

Asked by 8 years ago

I'm trying to get my DataStores to work, but there's a catch...

In the first server, when I use

local DataStore = game:GetService("DataStoreService"):GetDataStore("Departments")
local key = "user_" .. game.Players.TheHospitalDev.userId
print(DataStore:GetAsync(key))

It will print "N/A", which is correct.

I then change the value. It prints whatever the value was, correct.

I then rejoin the server, try to print it again. And it prints "N/A", not correct.

My script to change

local DataStore = game:GetService("DataStoreService"):GetDataStore("Departments")
local key = "user_" .. script.Parent.userId

script.Parent:WaitForChild("leaderstats").Department.Changed:connect(function()
    DataStore:UpdateAsync(key, function(department)
        local newValue = script.Parent.Parent.leaderstats.Department.Value
        return newValue
    end)
end)
1
make sure the newValue is not nil, and department (the argument) is also not nil, if department is nil, it means the key does not exist, if you return nil, the transaction is canceled. Make sure to sprinkle some prints around your script for debugging TheLowOne 85 — 8y

1 answer

Log in to vote
0
Answered by
LuaXYZ 5
8 years ago

You need to wait until the player's data is ready.

Player:WaitForDataReady()
Ad

Answer this question