Leaderboard of total most time played

so im trying to make a leaderboard in game on a literal board where you can scroll on and stuff with the most time played of top 100. i have these two scripts but i have no idea how to put it on a leaderboard

function onPlayerEntered(newPlayer)
    local stats = Instance.new("IntValue")
    stats.Name = "leaderstats"
    local captures = Instance.new("IntValue")
    captures.Name = "Time Played"
    captures.Value = 0
    captures.Parent = stats
    stats.Parent = newPlayer
	 wait(1)
	 captures.Value=captures.Value+1
	 wait(1) 
	 captures.Value=captures.Value+1
	 wait(1)
	 captures.Value=captures.Value+1
	 workspace.LinkedLeaderboard["Time Playing Counter"]:Clone().Parent=newPlayer.Backpack
	 workspace.LinkedLeaderboard["Time Playing Counter"]:Clone().Parent=newPlayer.StarterGear
end

game.Players.ChildAdded:connect(onPlayerEntered)

and inside this script the local script:

while wait(1) do
	game.Players.LocalPlayer.leaderstats["Time Played"].Value=game.Players.LocalPlayer.leaderstats["Time Played"].Value+1
end 

and so im guessing this is for the leaderboard upright, but i want to put it on a literal 3d leaderboard in the game

3 Likes

I’d recommend doing everything on the server-side just because on client-side players can exploit your value and also you can prevent many errors mistakes not seen value increased by the server because you are increasing value in local script.

function onPlayerEntered(newPlayer)
    local stats = Instance.new("IntValue")
    stats.Name = "leaderstats"
    local captures = Instance.new("IntValue")
    captures.Name = "Time Played"
    captures.Value = 0
    captures.Parent = stats
    stats.Parent = newPlayer
    workspace.LinkedLeaderboard["Time Playing Counter"]:Clone().Parent=newPlayer.Backpack
    workspace.LinkedLeaderboard["Time Playing Counter"]:Clone().Parent=newPlayer.StarterGear
end

game.Players.ChildAdded:Connect(onPlayerEntered)

while true do
  for i,v in pairs(game:GetService("Players"):GetChildren()) do
      v:FindFirstChild("leaderstats")["Time Played"].Value = v:FindFirstChild("leaderstats")["Time Played"].Value + 1
  end
wait(1)
end

so is this script the two scripts in one? where do i put it

you cannot change the leaderstats locally because the change will not be reflected on the server.

function onPlayerEntered(newPlayer)
    local stats = Instance.new("IntValue")
    stats.Name = "leaderstats"
    local captures = Instance.new("IntValue")
    captures.Name = "Time Played"
    captures.Value = 0
    captures.Parent = stats
    stats.Parent = newPlayer
	 wait(1)
	 captures.Value=captures.Value+1
	 wait(1) 
	 captures.Value=captures.Value+1
	 wait(1)
	 captures.Value=captures.Value+1
	 workspace.LinkedLeaderboard["Time Playing Counter"]:Clone().Parent=newPlayer.Backpack
	 workspace.LinkedLeaderboard["Time Playing Counter"]:Clone().Parent=newPlayer.StarterGear
     spawn(function()
           while wait(1) do
                 captures.Value = captures.Value + 1
           end
     end)
end

game.Players.ChildAdded:connect(onPlayerEntered)
1 Like

okay, where do i put this script?

This is full server script you can delete local script now.

its just kinda stuck at 3 it doesnt count anymore

Did you check the server side and not client side?

what do you mean (30characters)

You have a button in the studio which you can change the look of information from client-side and server side, here is the article. I don’t think you used my script because I don’t have a count to three at the start so that’s maybe the problem you used the other guy’s script or it’s just a mistake in mine source which I don’t really think it is.

im putting your script in a script now, local or normal

okay it works. how do i make sure it actually says time played instead of time… also is it really not possible to put this on a part inside of the actual game

the timer also resets when you rejoin

No. You should keep this script in ServerScriptService because it’s used as a Script storage. It also doesn’t need to wait for the part to load in.

If the timer resets when you rejoin, you’ll need to use DataStoreService, which saves data.

Put the script in server script service