Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I grab everyone's leaderstats?

Asked by 5 years ago

I'm trying to make a PVP Gun Fighting Game, I can make UI, and get a local player's leaderstats, but how do I see which player has the most kills after a game is done, I'm also wondering how to make a UI on the top that displays the top 5 players.

I would show a code example, as i slightly understand how to get the time part working, and how to detect a leaderstat value, math.random and such.

I'm not trying to request, please help.

I would show a code attempt here but I don't know how I would get the script to work, here's my best try:

local UI = script.Parent
local Player = game.Players
local Start = game.ServerScriptService
local GameEnded = Start.GameEnded -- I dont care if u change up the variables.

if Start.GameStarting.Value == true then
    UI.Text = "Game is starting in a few seconds..."
    wait(1)
    UI.Text = "Start!"
    wait(1) -- i think there's a better way to make time work, I remember it but can't remember how to write it, something with for i,v in pairs.
    UI.Text = "5:25"
    wait(1)
    UI.Text = "5:24"
    wait(1)
    UI.Text = "5:23"
    wait(1)
    UI.Text = "5:22"
    wait(1)
    UI.Text = "Finish!"
    -- how would i scan for all player leaderstats and display it in a UI?
end

Explorer: -- GameUI --- Frame ---- Other Health UI stuff. ---- Top Leaderboard Bar, (5 Players) ---- Timer (Below Bar)

The script is inside the timer UI, and the values are just simply placed in ServerScriptService.

2 answers

Log in to vote
1
Answered by
thesit123 509 Moderation Voter
5 years ago
Edited 5 years ago

If you are trying to get the player with the most kills then the code should be like this:

local killValueName = "Kills"  -- whatever your NumberValue is for Kills.. Change this to the correct name of the NumberValue

local mostKills = 0
local playerWithMostKills

for i, v in pairs(game.Players:GetDescendants()) do
    if v.Name == killValueName and v.Value > mostKills then -- checks if the name is correct and the player's kills is more than the previous player kills
        playerWithMostKills = v.Parent.Parent -- Parent to leaderstats, then the player
        mostKills = v.Value
    end
end
0
Make sure to update the "mostKills" variable. karlo_tr10 1233 — 5y
0
If you mean change it, yea after testing ill change it. RobloxGameingStudios 145 — 5y
0
half works, i have problems with the playerWithMostKills, i havent fully finished it yet, and it may be other code issues. Ill accept once i get it to work. RobloxGameingStudios 145 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

Hello, this will not directly answer your question but I think it could help. Here is a for loop.

Light = game.Workspace.Lights:GetDescendants("Light")

for i,Light in pairs(Light) do
    if Light.Name == "Light" then
        Light.PointLight.Enabled = false
        Light.BrickColor = BrickColor.new("Black")
    end
end

what this script does is it gets all of the descendants inside of a folder called Lights. Then the

for i,Light in pairs(Light) do 

is looping over and over to get all the descendants of the folder. Once it has all of the decendants, it can tell all of those lights to turn off. I hope this makes a little sense. I reccomend watching PeasFactory on youtube. He has 2 videos, for loops for beginners and for loops in pairs tutorial. Enjoy!

0
so what you could do is get all of the Descendants of Players and run a check with a for loop for the highest Value at the end of the match :) guywithapoo 81 — 5y
0
hmm ill try that out RobloxGameingStudios 145 — 5y
0
I dont get how I'm supposed to go in and scan all player's kill values and see which is the biggest, if I have to go by a pre-set value instead of time, I can, please help RobloxGameingStudios 145 — 5y

Answer this question