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

How Can I Print The First Player's Name?

How Can I Print the First/Second Player's name on the table?

local playersInRedRoom = {}
clickJoinGreenRoom.MouseClick:Connect(function(player)
		if #playersInRedRoom < 2 then
		table.insert(playersInRedRoom, player.Name)

print("The Player "..playersInRedRoom[2].Player.Character.Name.."Two Got a Point!")

2 answers

From what I see, you're inserting the player's name into the table (a string), but when you call it back, you treat it as a player instance.

local playersInRedRoom = {}
clickJoinGreenRoom.MouseClick:Connect(function(player)
        if #playersInRedRoom < 2 then
        	table.insert(playersInRedRoom, player.Name)
		print("The Player "..playersInRedRoom[2].."Two Got a Point!")
	end
end)

Treating it as a string should work. (I also noticed that a couple ends was missing, so I added those.)

1 comment

0

I tried it and it didn't work, can you add me Discord Aft3rL1fe#8610 I'm trying to get this done for literally 1 week now :(

If the if statement is true, then that means there's 0 or 1 values in variable playersInRedRoom. So when you add the second or first name, you either get two or one value in variable playersInRedRoom. I would use #playersInRedRoom to get the latest value.

local playersInRedRoom = {}
clickJoinGreenRoom.MouseClick:Connect(function(player)
	if #playersInRedRoom < 2 then
		table.insert(playersInRedRoom, player.Name)
		print("The Player "..playersInRedRoom[#playersInRedRoom].."Two Got a Point!")
	end
end)

2 comments

0

Let's say there are 5 Players, how would you define the 4th player, this is what I'm asking

0

are you asking if its four players as in constant or one below the total?

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