Hello! I need help at this because I am not too advance and I’ve tried working on many scripts for this crap. I need help with making a script that set’s all players BoolValue that’s called “Lead” and who ever has the highest kills on the classic leaderboard would get their BoolValue set to true while everyone’s false.
This is so that right when the Round is over it checks who has their value set to true and give them a win and all of their stats just resets.
PSEUDO CODE
IDENTIFY A TABLE
EVENT THAT IS FIRED AFTER EVERY KILL (PLAYERID)
CHECK IF TABLE HAS KEY OF PLAYERID
RAISE TABLE[PLAYERID] BY ONE
ELSE
CREATE VALUE OF TABLE[PLAYERID] EQUAL TO ONE
END
The PLAYERID parameter is the person who got the kill.
Why do you need a BoolValue for each player? Can’t you just use a ModuleScript to get the best player?
local module = {}
function module.getBestPlr()
local highest = {plr = nil,value = 0}
for _, p in game.Players:GetPlayers() do
if p.leaderstats.Kills.Value > highest.value then
highest.value = p.leaderstats.Kills.Value
highest.plr = p
end
end
end
return module
-- in another script
local module = require(game.ReplicatedStorage.ModuleScript)
local best = module.getBestPlr()
print(best.plr,best.value)
The reason why I am doing this way it’s because I am using an older system for this round thing but It’s really good. I am just replacing it because the way it worked was the people who are still in the round has it enabled but I am trying to replace it only a player with the most kills will have it Enabled.
Ok, I get what you mean. Something like this should work.
local module = {}
function module.getBestPlr()
local highest = {plr = nil,value = 0}
for _, p in game.Players:GetPlayers() do
if p.leaderstats.Kills.Value > highest.value then
highest.value = p.leaderstats.Kills.Value
highest.plr = p
end
end
if highest.plr then
highest.plr.Lead.Value = true
end
end
return module
This won’t work because plr and value would both be nil and 0 because it has not been set yet. If I were to replace that code, I would compile all kill values with their indexes being their player names or another setup could be an array that has this: {"John_Doe", 9}. Then, it’s just simply compare and find the highest value. I hope you understand what I said.
Thanks but I sort of understood on what you mean by, I am not that advanced when it comes to this so I am still confused on how I should make a script like this.
local List = {}
local HighestValue = 0
local PlayerWithTheHighestKills = ""
for _, Player in pairs(Players:GetPlayers()) do
List[Player.Name] = Player.leaderstats.Kills.Value
end
-- Get the highest value
for Name, Value in pairs(Value) do
if HighestValue < Value then
HighestValue = Value
PlayerWithTheHighestKills = Name
end
end
print(PlayerWithHighestKills)