Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why doesn't this work?(I'm trying to add KOs to a table)

	for i,v in pairs(game.Players:GetPlayers()) do 
		t1 = {}
		KO = v.leaderstats.KOs.Value
		 table.insert(t1,#t1+1,KO)			
	end
			table.sort(t1)
				print(t1[#t1])

is part of

local GameModes = {}

function FreeForAll()
	for i,v in pairs(game.Players:GetPlayers()) do 
		Firefox = {}
		zenox = v.leaderstats.Value
		 table.insert(Firefox,zenox, #Firefox + 1)
			table.sort(Firefox)
			print(Firefox[#Firefox])
			
	end
	end

function MultiTeam()
	
end

function Choosemode(Mapchosen)
	if Mapchosen == "Sol2" then
		FreeForAll()
		print("Sol2")
	end
	
	if Mapchosen == "ArenavonOsterreich" then
		MultiTeam()
		print("ArenavonOsterreich")
	end

end




return GameModes

So I'm trying to get the player with the highest KO value right?

Problem is, It's not working,

The highest value of KOs is 5, yet it prints "0" instead No errors in the output.

Help me out here. Thanks in advance

4 comments

0

is this the whole of your code? and you can use the unpack method to see the content of a table e.eg print(unpack(t1))

0

Yeah it is, it's part of a module script.

0

Can you put all of the module script in?

0

Hey if you think it would help, fine

1 answer

✓ Accepted answer

Here's my way to get the highest KO's...

local KOs = "KOs" -- Insert the name of your KOs value
local highestKOs = 0
local Player

for index,returned in ipairs(game.Players:GetChildren()) do
	if returned:FindFirstChild("leaderstats") and returned.leaderstats:FindFirstChild(KOs) then
		if returned.leaderstats[KOs].Value > highestKOs then
			Player = returned.Name
			highestKOs = returned.leaderstats[KOs].Value
		end
	end
end

print("Player: "..Player.." // KOs: "..highestKOs)

This will get the player with the highest KOs.

This discussion is preserved as it was. New answers, comments, and votes are closed.