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

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

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?

3 comments

0

Well, what's activecontestants?

0

I don't think it matters. Looks like he wants to know how he can print the table.

0

Please show the full script.

1 answer

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

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