Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 8 years ago
    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

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)) User#5423 17 — 8y
0
Yeah it is, it's part of a module script. ClusterStudios 5 — 8y
0
Can you put all of the module script in? User#5423 17 — 8y
0
Hey if you think it would help, fine ClusterStudios 5 — 8y

1 answer

Log in to vote
0
Answered by
Scarious 243 Moderation Voter
8 years ago

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.

Ad

Answer this question