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.
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
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!