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

How would I get the name of the active players still standing in my game?

Asked by 9 years ago
for _, player in pairs(contestants) do
        if #contestants < 2 then
        local gameresults = player.Character.Name.." wins!"
        print(gameresults)
        elseif #contestants >= 2 then
            local winners = activecontestants
            print("Winners: "..winners)
            mapholder:ClearAllChildren()
        end
    end

Here's a snippet of my code. How would I get the names of the activecontestants?

0
Well, what's activecontestants? Perci1 4988 — 9y
0
I don't think it matters. Looks like he wants to know how he can print the table. aquathorn321 858 — 9y
0
Please show the full script. yoshiegg6 176 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

Use a for loop:

local winners = ""
for i = 1, #activecontestants do
    winners = winners .. activecontestants[i].Name
    if i < #activecontestants - 1 then --add a comma after every entry except the last two
        winners = winners .. ", "
    elseif i ~= #activecontestants then --after the second last one, add an "and"
        winners = winners .. ", and "
    end
end
Ad

Answer this question