0

# How do i check if a specific player presses a key?

as the title said, how do i check if a specific player presses a key? Ive tried to do

local cool = {"Cill_Roblox"}
local gui = script.Parent

if player.Name == cool then
if game:GetService("UserInputService"):IsKeyDown(Enum.KeyCode.L) then
gui.Enabled = true
end
end
end)


but that doesnt work since playeradded only checks once as far as i know and

local cool = {"Cill_Roblox"}
local gui = script.Parent
local guy = false
local uis = game:GetService("UserInputService")

if player.Name == cool then
guy = true
end
end)

uis.InputBegan:Connect(function(input, gameProccesedEvent)
if input.UserInputType == Enum.KeyCode.L then
if guy == true then
gui.Enabled = true
end
end
end)


ive tried looking stuff like "how to check if specific player presses a key roblox" but found nothing on this so far. anyone know something about this? any help is appreciated

0
UIS does not function on the server, it's client-only DeceptiveCaster 3761 — 13d

0

first of all, you need to make sure that the UserInputService part is in a local script as it's client-side only, second of all, try using the InputBegan event to toggle the gui instead of checking if a key is being held down.

example:

gui = script.Parent
userInputService = game:GetService("UserInputService")

userInputService.InputBegan:Connect(function(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.L and game.Players.LocalPlayer.DisplayName == "Cill_Roblox" then
gui.Enabled = true
end)