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

How to define a players name in a variable?

I am needing to make a _G variable that can hold the players name and then use the print statement in another script.. Can you help?

1 comment

1

In a local or normal script?

1 answer

✓ Accepted answer

You can create the variable on PlayerAdded, like this:

local Players = game.Players

Players.PlayerAdded:Connect(function(playerWhoJoined)
	_G.LastPlayerToJoinGame = playerWhoJoined.Name
end)

Obviously, this is gonna get overwritten each time someone new joins, so we'll need to build onto this a bit if you wanna store the names of everyone who joins. However if that's the case you're better off just keeping what you need in your PlayerAdded, and passing the player as an argument to other scripts through events for other things you may need.

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