Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

is this possible or not? (user input service)

Asked by 6 years ago
Edited 6 years ago
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

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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

Ad

Answer this question