How would I make this script?

Hello everyone!

I was trying to make a system where if your the top on the leaderboard ( works with ordered datastore )

and the keys are saved as user ids of the player and I wanted to make it so if your at the top of the leaderboard you get a tool when you log on

the leaderboard script is already made I just want to make it so you get a tool if your at the top at the leaderboard

local DSS = game:GetService("DataStoreService")
local dataStore = DSS:GetOrderedDataStore("Global_Leaderboard")

Please help me code this script because I just dont know how I could do this.

local topPlayer = pcall(dataStore.GetAsync, dataStore, 1)

Players.PlayerAdded:Connect(function(plr)

    if plr.UserId == topPlayer.key then

        -- give them tool
    end
end)

ill test this later and make a tool clone into players backpack thank you

1 Like