Will this work?

for _,player in pairs(game.Players:GetChildren()) do
		for _,Card in pairs(game.Workspace.GlobalLeaderboard.Screen.MainFrame:GetChildren()) do
			if Card:IsA("Frame") then
				Card:Destroy()
			end
		end
		local GlobalScore = TopPlayersLeaderboard:GetAsync(player.UserId)
		if GlobalScore < player.Stats.CurrentDays.Value then
			TopPlayersLeaderboard:SetAsync(player.UserId, player.Stats.CurrentDays.Value)
		elseif GlobalScore == nil then
			TopPlayersLeaderboard:SetAsync(player.UserId, 0)
		end
		updateLeaderboard()
	print("Done!")
end

This script is updating a leaderboard.

if GlobalScore < player.Stats.CurrentDays.Value then
TopPlayersLeaderboard:SetAsync(player.UserId, player.Stats.CurrentDays.Value)
elseif GlobalScore == nil then
TopPlayersLeaderboard:SetAsync(player.UserId, 0)
end

Now I just want to know if this statement is valid or not… Will it work or not.

I dont know if i try to get a new players datastore without assigning it previously to a value does it return nil or something else. So I made sure if GlobalScore == nil that means If he is a new player then make SetAsync to 0… I want to know if it works or not since I can’t test it…

pcall function pliz, there is the chance that GlobalScore can return back nil especially if there’s no data found in that specific player

for _,player in pairs(game.Players:GetChildren()) do
	for _,Card in pairs(game.Workspace.GlobalLeaderboard.Screen.MainFrame:GetChildren()) do
		if Card:IsA("Frame") then
			Card:Destroy()
		end
	end
    local GlobalScore

    local success, whoops = pcall(function()
	    GlobalScore = TopPlayersLeaderboard:GetAsync(player.UserId)
    end)

    if success and GlobalScore then
        if GlobalScore < player.Stats.CurrentDays.Value then
            TopPlayersLeaderboard:SetAsync(player.UserId, player.Stats.CurrentDays.Value)
        else
            TopPlayersLeaderboard:SetAsync(player.UserId, 0)
        end
    end
    updateLeaderboard()
    print("Done!")
end
1 Like