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

Could I have some help with _G? I'm trying to use it... My current script is not working.

I am trying to use _G to print out a PlayerAdded piece of code which should print out the players name when they join.

Script !:

game.Players.PlayerAdded:Connect(function(playerName)
	
	_G.PlayerName = playerName
end)

script 2:

print(_G.PlayerName)

1 comment

0

_G is privy to it's end of the spectrum. If defined on the Server, it is inaccessible to the Client. You're also allocating the Player Instance, not their name: _G.PlayerName = Player.Name*

1 answer

For This Script Global Varibles Don't Need To Be Used As You Can See Below.

Try This Instead:

game.Players.PlayerAdded:Connect(function(player)  -- Runs when a player joins the game
   local PlayerName = player.Name -- Gets the players name
	print(PlayerName) -- Prints the players name
end) -- Ends the function

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