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

DataStores not updating, any help?

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

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

1 answer

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

Player:WaitForDataReady()

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