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)
You need to wait until the player's data is ready.
Player:WaitForDataReady()