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 comment
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