So i tried searching but i couldn't have seen any ways to do it, I want to make a leaderboard for "Most time wasted" and I want to paste it onto a surface gui, but how?
✓ ANSWER ACCEPTED
How to make a leaderboard the gives 1 point every 1 second?
1 answer
✓ Accepted answer
for the leaderboard simple:
-- script, ServerScriptService
game.Players.PlayerAdded:Connect(function(player) -- when player joins
local leaderstats = Instance.new("IntValue", player) -- makes leaderstats
leaderstats.Name = "leaderstats" -- dont change the name of it
local timeSpent = Instance.new("IntValue", leaderstats) -- makes stat for most time played
timeSpent.Name = "Time Wasted" -- name of stat (if your game is waste of time then why do you make it?)
while true -- makes loop
do timeSpent.Value = timeSpent.Value + 1 -- adds 1 value
wait(1) -- per second
end
end)
This is how you get the stat, to paste it onto surface gui you need to get the label and set its value to the stat value.
EDIT:
game.Players.PlayerAdded:Connect(function(player)
local timeSpent = player:WaitForChild"Time Spent" -- name of leaderstat
timeSpent.Changed:Connect(function(newTime)
script.Parent.Text = newTime
end)
end)
This script is probably not what you need but i don't know what do you want to implement so bassicaly if you put this into textlabel you need then it will show amount of leaderstats of first player that joins, if there are two then it will break but again idk what do you want to implement so this is just example. if you for example want it only for one player always then change line:
local timeSpent = game.Players.Jack:WaitForChild"Time Spent" -- name of leaderstat
change the jack to one player you need but it's again just an example.
This discussion is preserved as it was. New answers, comments, and votes are closed.

5 comments
How would i make it saved?
Use data store for that
Thanks.
Also how do i past it onto a Surface Gui?
I have made example, but i don't know what do you want to make so i can not fully help but just explain it a little.