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

How do I get a single player from 'game.Players' on a 1-person server without it being a table?

Yes, I know that was a long title. Sorry! But anyhow, this one should be pretty simple. Say I had a 1 person server. If I wanted to get the player himself from game.Players using the following code, how would I be able to script it without it being considered a table?

local plr = game.Players:GetPlayers()

As an example, if I needed something specific from the user, such as his unique user ID, how would I get the user data instead of a table with only him on it?

local key = "user_" .. plr.userId

I tried this in a bit of code I made for my game, and I end up getting a related error.

The error states: "Workspace.script:line#: attempt to concatenate field 'userId' ( a nil value )"

Concatenation is a term used with tables, hence why I made the assumption that it's being read as a table and not the specific user.

I hope this makes sense! Thanks for the help in advance.

1 answer

✓ Accepted answer

Use the PlayerAdded Event

This will get incoming players.

game.Players.PlayerAdded:connect(function(plr)
	local key = "user_"..plr.UserId
end)

Good Luck!

Short pathetic answer for your fancy

1 comment

0

LOL. ok! I didn't know that the playeradded function kept running too until all parts of it are completed, veryyy nice to know!

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