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

is this possible or not? (user input service)

function onKeyPress(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == Enum.KeyCode.Return then
		--trying to get the player's name here. 
	end
end
 
game:GetService("UserInputService").InputBegan:Connect(onKeyPress)

would it be possible to get the player's name from this? (server script in ServerScriptService)

or would i have to do this another way?

1 answer

✓ Accepted answer

Hey RobloxianDestroy,

You can easily get the Player's name if you simply use a LocalScript and make sure it's on the Client side. This means that the script's parent needs to be either of the following:

StarterGui

StarterPack

StarterPlayerScripts

StarterCharacterScripts

###Now then, after you have placed the LocalScript inside of the Client, you must access the player by using LocalPlayer. Like so:

####Example A

local player = game.Players.LocalPlayer;

###After you have done that, you just need to print the player's name inside of the function. Below is an example for this.

####Example B

local player = game.Players.LocalPlayer;
local uis = game:GetService("UserInputService");

uis.InputBegan:Connect(function(object, gp)
	if object.KeyCode == Enum.KeyCode.Return and not gp then
		print(player.Name);
	end
end)

##Well, I hope I helped and have a wonderful day/night.

~~ KingLoneCat

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