What is the “Stats” Data ?
It might not be Greater than your Data Store Value
What is the “Stats” Data ?
It might not be Greater than your Data Store Value
If there is no error message from printing the two variables then I don’t know what’s wrong.
The other possibility though is that if it’s your first time calling Data:GetAsync(v.UserId)
for that person, you’re going to return nil and it will error if you try and compare nil and number.
Stats is the current reign in the datastore which is stored in server storage.
It is not the first time because the leaderboard loads my previous data but not the updated data.
Could you try using
Data:GetAsync(tostring(v.UserId))
Also is the Stats Data a Boolean Value(True or false) or some other Data Type(Number, String Vector3, etc)
hm that might work because everything is set has number values.
No it still does not work, nothing is getting past the if statement.
What Value is stored in “Stats” ? as i said before it might not be greater than the Data Store Value
The data store is called monthlyReignLeaderboard V:1
Ok well what is the Value of “Stats” ?
The value of stats is how long the player was alive before dieing. I do the < so the value would not decrease its best time.
Stats is a built in roblox function try renaming your Variable
still getting nil even though I changed this.
Are you using “pcall()” correctly ?
it should look something like this
local success, err = pcall(function()
-- Your stuff here
end)
if not success then
print(err)
end
yeah, I alr did this and there’s was no errormessage
could i see your updated version of the script ?
with the pcall’s and stuff added ?
also try using <= if it gets past then you can do some math operations to make it just like this <
local success, errormessage = pcall(function()
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
RetrievedData = Data:GetAsync(v.UserId)
print(RetrievedData)
if Stats then
print(Stats)
pcall(function()
if Stats >= RetrievedData then
DataStore:UpdateAsync(v.UserId, function(Value)
return tonumber(Stats)
end)
end
end)
end
end
I have this in a loop
Oh you are putting the new “pcall()” in the wrong place replace second one with the first then remove the first
then there might be errors in the output
Workspace.MonthlyReignLeaderboard.MonthlyReignLeaderboardScript:67: attempt to compare nil and number
it is saying the data is nil when it should be 7