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 » Scripters
Home Search
 

Re: Tables

Previous Thread :: Next Thread 
PureVoid is not online. PureVoid
Joined: 25 Dec 2011
Total Posts: 2624
19 Aug 2015 04:28 PM
I'm trying to make a table so that it will eventually give who has the most kills in a server. This isn't right, but this is what I have so far.

for _, player in pairs(game.Players:GetPlayers()) do
local l = player["leaderstats"]
for index, child in pairs(l:GetChildren()) do
print(math.max(index, child.KOs.Value))
end
end

how should I go about so I can continue this?
Report Abuse
PureVoid is not online. PureVoid
Joined: 25 Dec 2011
Total Posts: 2624
19 Aug 2015 04:29 PM
b1
Report Abuse
DeathsLASTwords is not online. DeathsLASTwords
Joined: 28 Jan 2012
Total Posts: 2701
19 Aug 2015 04:29 PM
for _, player in pairs(game.Players:GetPlayers()) do
local l = player["leaderstats"]
for index, child in pairs(l:GetChildren()) do
print(math.max(index, child.KOs.Value))
end
end

id recommend changing l to a different variable
Report Abuse
PureVoid is not online. PureVoid
Joined: 25 Dec 2011
Total Posts: 2624
19 Aug 2015 04:31 PM
ok, I'll try that
Report Abuse
PureVoid is not online. PureVoid
Joined: 25 Dec 2011
Total Posts: 2624
19 Aug 2015 04:32 PM
b2
Report Abuse
PureVoid is not online. PureVoid
Joined: 25 Dec 2011
Total Posts: 2624
19 Aug 2015 04:34 PM
b3
Report Abuse
PureVoid is not online. PureVoid
Joined: 25 Dec 2011
Total Posts: 2624
19 Aug 2015 04:38 PM
b4

pls help
Report Abuse
instawin is not online. instawin
Joined: 04 Jun 2013
Total Posts: 8777
19 Aug 2015 04:39 PM
local function getDeadliestPlayer()

local function gatherKillsData()
local killsTab = {}
for i, v in ipairs(game.Players:GetPlayers()) do
local ls = v:FindFirstChild("leaderstats")
if ls then
local kills = ls:FindFirstChild("Kills")
if kills then
table.insert(killsTab, kills.Value)
end
end
end
return killsTab
end

local totalKills = gatherKillsData()
local mostKills = math.max(totalKills)

for i, v in ipairs(game.Players:GetPlayers()) do
if v.leaderstats.Kills.Value == mostKills then
return v
end
end

end

local deadlyPlayer = getDeadliestPlayer()
print(deadlyPlayer.Name)
Report Abuse
PureVoid is not online. PureVoid
Joined: 25 Dec 2011
Total Posts: 2624
19 Aug 2015 04:40 PM
I'll try that out

Thanks a lot!
Report Abuse
PureVoid is not online. PureVoid
Joined: 25 Dec 2011
Total Posts: 2624
19 Aug 2015 04:41 PM
I got this from output:

17:41:08.001 - ServerScriptService.Most KOs/WOs/Points Script:18: bad argument #1 to 'max' (number expected, got table)
17:41:08.003 - Script 'ServerScriptService.Most KOs/WOs/Points Script', Line 18 - local getDeadliestPlayer
17:41:08.004 - Script 'ServerScriptService.Most KOs/WOs/Points Script', Line 28
17:41:08.005 - Stack End
Report Abuse
instawin is not online. instawin
Joined: 04 Jun 2013
Total Posts: 8777
19 Aug 2015 04:44 PM
whoops, my bad
forgot to call unpack

local mostKills = math.max(unpack(totalKills))
Report Abuse
PureVoid is not online. PureVoid
Joined: 25 Dec 2011
Total Posts: 2624
19 Aug 2015 04:46 PM
I put that in again, but I got this:

ServerScriptService.Most KOs/WOs/Points Script:18: bad argument #1 to 'max' (number expected, got no value)
17:45:05.957 - Script 'ServerScriptService.Most KOs/WOs/Points Script', Line 18 - local getDeadliestPlayer
17:45:05.957 - Script 'ServerScriptService.Most KOs/WOs/Points Script', Line 28
17:45:05.958 - Stack End
Report Abuse
instawin is not online. instawin
Joined: 04 Jun 2013
Total Posts: 8777
19 Aug 2015 04:48 PM
then that means the table is empty, and you don't have a leaderstats or a Kills value in leaderstats
Report Abuse
instawin is not online. instawin
Joined: 04 Jun 2013
Total Posts: 8777
19 Aug 2015 04:51 PM
put this line under the local totalKills line:

print(unpack(totalKills))

and tell me what it prints
Report Abuse
PureVoid is not online. PureVoid
Joined: 25 Dec 2011
Total Posts: 2624
19 Aug 2015 05:27 PM
ok I will
Report Abuse
PureVoid is not online. PureVoid
Joined: 25 Dec 2011
Total Posts: 2624
19 Aug 2015 06:30 PM
local function getDeadliestPlayer()

local function gatherKillsData()
local killsTab = {}
for i, v in ipairs(game.Players:GetPlayers()) do
local ls = v:FindFirstChild("leaderstats")
if ls then
local kills = ls:FindFirstChild("KOs")
if kills then
table.insert(killsTab, kills.Value)
end
end
end
return killsTab
end

local totalKills = gatherKillsData()
print(unpack(totalKills))
local mostKills = math.max(unpack(totalKills))

for i, v in ipairs(game.Players:GetPlayers()) do
if v.leaderstats.Kills.Value == mostKills then
return v
end
end

end

local deadlyPlayer = getDeadliestPlayer()
print(deadlyPlayer.Name)



19:29:46.890 - ServerScriptService.Most KOs/WOs/Points Script:19: bad argument #1 to 'max' (number expected, got no value)
19:29:46.893 - Script 'ServerScriptService.Most KOs/WOs/Points Script', Line 19 - local getDeadliestPlayer
19:29:46.893 - Script 'ServerScriptService.Most KOs/WOs/Points Script', Line 29
19:29:46.894 - Stack End
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
19 Aug 2015 06:32 PM
The easy method:

local players = game.Players:GetPlayers();
table.sort(players, function(val1, val2)
return val1.KOs.Value < val2.KOs.Value;
end);

print("The person with the most KOs is: " .. players[1].Name);
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
19 Aug 2015 06:33 PM
Woops
return val1.KOs.Value > val2.KOs.Value;
Report Abuse
instawin is not online. instawin
Joined: 04 Jun 2013
Total Posts: 8777
19 Aug 2015 06:34 PM
lel, use cnt's

can't believe i didn't think of that
Report Abuse
PureVoid is not online. PureVoid
Joined: 25 Dec 2011
Total Posts: 2624
19 Aug 2015 06:34 PM
I'll try that one
Report Abuse
PureVoid is not online. PureVoid
Joined: 25 Dec 2011
Total Posts: 2624
19 Aug 2015 06:37 PM
I tried cnts, it gives off this:

(It's line 40 now because I just made insta's script a comment)

19:34:25.311 - ServerScriptService.Most KOs/WOs/Points Script:40: attempt to index field '?' (a nil value)
19:34:25.314 - Stack Begin
19:34:25.315 - Script 'ServerScriptService.Most KOs/WOs/Points Script', Line 40
19:34:25.316 - Stack End
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
19 Aug 2015 06:37 PM
which line is 40?
Report Abuse
PureVoid is not online. PureVoid
Joined: 25 Dec 2011
Total Posts: 2624
19 Aug 2015 06:39 PM
print("The person with the most KOs is: " .. players[1].Name);
Report Abuse
instawin is not online. instawin
Joined: 04 Jun 2013
Total Posts: 8777
19 Aug 2015 06:41 PM
make sure you yield until a player has joined the server at least, if this is literally your whole script..

game.Players.PlayerAdded:wait()
Report Abuse
Darkenus is not online. Darkenus
Joined: 17 Jul 2014
Total Posts: 1997
19 Aug 2015 06:42 PM
Cnt
Why do you like to put semicolons after your code. This isnt Java/C++/etc. Don't you find it tedious?
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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