generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Comparing leader stats to determine who has the most kills.

Previous Thread :: Next Thread 
0ultimoKILLER is not online. 0ultimoKILLER
Joined: 31 Aug 2011
Total Posts: 1542
06 Feb 2013 01:11 PM
For my game I have a freeforall game mode and in that i need to get all the leaderstats of players playing and return who has the highest kills.
Please could someone help by telling me how to go about this.
Report Abuse
Azarth is not online. Azarth
Joined: 17 Aug 2012
Total Posts: 2760
06 Feb 2013 02:03 PM
No, but I'll tell you how you can do it.

Make a variable/value that you can use to compare against; a high score variable.

Make a table so you can insert the person with the highest score each time it surpasses the next persons score.

Use a for loop to run through the player's scores. When a person's stats surpasses the high score value, clear the table, add them to the table, and make the HS value their score.

Then when that's done make sure the player in the table is still in the game and announce the player in the table.

--Note, I didn't go over what you do when people tie. I'd start with something like this first, before tackling multiple winners.
Report Abuse
0ultimoKILLER is not online. 0ultimoKILLER
Joined: 31 Aug 2011
Total Posts: 1542
06 Feb 2013 02:19 PM
Thanks Azarth

This is what I came up with. No idea if it will work because unexpected symbol near = error on this line playerstats(#playerstats+1) = v.Value.leaderstats.Kills.Value any ideas? And do you think it could work?

FreeForAll = function()
wait(180)
for i,v in pairs (game.Players:GetPlayers()) do
playerstats(#playerstats+1) = v.Value.leaderstats.Kills.Value
highestkills = table.maxn(playerstats)
end

for i,c in pairs ((game.Players:GetPlayers()) do
if c.Value.leaderstats.Kills.Value = highestkills then
winner(#winner+1) = c.Value
winner.leaderstats.Money.Value = winner.leaderstats.Money.Value +40
end
end

if #winner = 1 then
local message = Instance.new('Message', game.Workspace)
message.Text= "Winner = ".. winner
wait(5)
message:Destroy()
end
end
Report Abuse
0ultimoKILLER is not online. 0ultimoKILLER
Joined: 31 Aug 2011
Total Posts: 1542
06 Feb 2013 02:29 PM
Ok updated my code so all errors are fixed apart from two lines problem with this playerstats(#playerstats+1) and winner(#winner+1).

FreeForAll = function()
wait(180)
for i,v in pairs (game.Players:GetPlayers()) do
playerstats(#playerstats+1) = v.Value.leaderstats.Kills.Value
highestkills = table.maxn(playerstats)
end
for i,c in pairs (game.Players:GetPlayers()) do
if c.Value.leaderstats.Kills.Value == highestkills then
winner(#winner+1) = c.Value
winner.leaderstats.Money.Value = winner.leaderstats.Money.Value +40
end
end

if #winner == 1 then
local message = Instance.new('Message', game.Workspace)
message.Text= "Winner Of This Round Is ".. winner
wait(5)
message:Destroy()
end
end
Report Abuse
0ultimoKILLER is not online. 0ultimoKILLER
Joined: 31 Aug 2011
Total Posts: 1542
06 Feb 2013 02:33 PM
FIXED IT I WAS USIN THESE () INSTEAD OF THESE [] now to test!
UPDATED CODE =

FreeForAll = function()
wait(180)
for i,v in pairs (game.Players:GetPlayers()) do
playerstats[#playerstats+1] = v.Value.leaderstats.Kills.Value
highestkills = table.maxn(playerstats)
end
for i,c in pairs (game.Players:GetPlayers()) do
if c.Value.leaderstats.Kills.Value == highestkills then
winner[#winner+1] = c.Value
winner.leaderstats.Money.Value = winner.leaderstats.Money.Value +40
end
end

if #winner == 1 then
local message = Instance.new('Message', game.Workspace)
message.Text= "Winner Of This Round Is ".. winner
wait(5)
message:Destroy()
end
end
Report Abuse
Azarth is not online. Azarth
Joined: 17 Aug 2012
Total Posts: 2760
06 Feb 2013 02:37 PM
Their are a lot of errors in that, I'll try and push you towards the right direction. There will be errors in this, I gave you a lot, so try and fix them.

local hs = 0
local winner = {}

function ffa()
local p = game.Players:GetPlayers()
for i = 1, #p do
if plrs[i]:findFirstChild("leaderstats") then
local kos = plrs[i].leaderstats.KOs
if kos.Value >= hs and kos.Value ~= 0 then --If people tie, this won't weed them out.
hs = kos.Value
winner = {}
table.insert(winner, plrs[i].Name)
end
end
end
if game.Players:findFirstChild(winner[1]) then
local win = tostring(game.Players:findFirstChild(winner[1]))
local msg = Instance.new("Message", Workspace)
msg.Text = game.Players:findFirstChild(winner[1]).. " has won with " ..win.leaderstats.KOs.Value.. "!"
game.Debris:AddItem(msg, 3)
end
end
Report Abuse
Azarth is not online. Azarth
Joined: 17 Aug 2012
Total Posts: 2760
06 Feb 2013 02:38 PM
woops forgot I switched from plrs to p

local hs = 0
local winner = {}

function ffa()
local p = game.Players:GetPlayers()
for i = 1, #p do
if p[i]:findFirstChild("leaderstats") then
local kos = p[i].leaderstats.KOs
if kos.Value >= hs and kos.Value ~= 0 then --If people tie, this won't weed them out.
hs = kos.Value
winner = {}
table.insert(winner, p[i].Name)
end
end
end
if game.Players:findFirstChild(winner[1]) then
local win = tostring(game.Players:findFirstChild(winner[1]))
local msg = Instance.new("Message", Workspace)
msg.Text = game.Players:findFirstChild(winner[1]).. " has won with " ..win.leaderstats.KOs.Value.. "!"
game.Debris:AddItem(msg, 3)
end
end
Report Abuse
0ultimoKILLER is not online. 0ultimoKILLER
Joined: 31 Aug 2011
Total Posts: 1542
06 Feb 2013 03:04 PM
I get an error in output argument 1 missing or nil. I've been trying to to get passed that to no avail.
Report Abuse
Azarth is not online. Azarth
Joined: 17 Aug 2012
Total Posts: 2760
06 Feb 2013 03:14 PM
I'd try to see what's wrong, but studio won't stop crashing for me.
Report Abuse
Zakarii is not online. Zakarii
Joined: 03 Aug 2009
Total Posts: 102
06 Feb 2013 03:18 PM
That happened on a Win 7 computer for me. I'll try it out, and get back to you.
Report Abuse
Zakarii is not online. Zakarii
Joined: 03 Aug 2009
Total Posts: 102
06 Feb 2013 03:19 PM
ffs, it just started crashing for my XP.
Report Abuse
0ultimoKILLER is not online. 0ultimoKILLER
Joined: 31 Aug 2011
Total Posts: 1542
07 Feb 2013 09:09 AM
When studio stops crshing can you guys please give me an idea why I get that error. It'd be much appreciated thanks!
Report Abuse
0ultimoKILLER is not online. 0ultimoKILLER
Joined: 31 Aug 2011
Total Posts: 1542
07 Feb 2013 11:55 AM
bump!
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image