Hello!
I have been trying to compare DataStore data and I could not figure out how. Please help!
script
for i, v in pairs(game.Players:GetPlayers()) do
local Data = game:GetService("DataStoreService"):GetDataStore("MonthlyReignLeaderboard V:"..script.Parent.Version.Value)
local Stats = game.ServerStorage.PlayerData:WaitForChild(v.Name).CurrentReign.Value
if Stats then
pcall(function()
if Data:GetAsync(v.UserId) < Stats then
DataStore:UpdateAsync(v.UserId, function(Value)
return tonumber(Stats)
end)
end
end)
end
end
Could you try using “print()” statements and screenshot your output ?
btw add a “print()” statements after these:
the “for” loop
the “if Stats then”
the “pcall(function()”
the “if Data:GetAsync(v.UserId) < Stats then”
You should check if you have any saved data, or assign a default value to it, otherwise it will obviously be nil as there isn’t any data stored in the datastore key.
It seems like you are calling the tonumber function on Stats. Is it possible that when you are doing Data:GetAsync(v.UserId) < Stats, you are comparing two different data types?
If so that would cause an error. To check for errors in a pcall, you have to get the return value.
So you should do local success, message = pcall(function()...and print the success and message.