Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make a leaderboard the gives 1 point every 1 second?

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?

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.

5 comments

0

How would i make it saved?

0

Use data store for that

0

Thanks.

0

Also how do i past it onto a Surface Gui?

0

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.