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

How do I determine the player who input the key in UserInputService?

Asked by
u_g 90
9 years ago

So, for a game, I wanted to use a function that fires every time a player presses one. Except, it must be a specific player. Is there any way that I can figure out the player that is doing the input, during the event of InputBegan and InputEnded?

1 answer

Log in to vote
0
Answered by 9 years ago

UserInputService is a service only accessible in localscripts, and localscripts can also view a property of the Players service that tells you what player the script is owned by

local player = game.Players.LocalPlayer -- the player

local uis = game:GetService("UserInputService")

uis.InputBegan:connect(function()
    print(player.Name..' pressed something')
end)
0
Are you sure that they can only be accessed in LocalScripts? I used it on a normal script, and it worked perfectly, but only while running in Studio. u_g 90 — 9y
0
Yes, It'll work in studio but as soon as you do a server test or run it in game it won't work. It's best to not ever use it in server scripts YellowoTide 1992 — 9y
Ad

Answer this question