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

UserInputService does not detect input?

I've made a script that detects when a specific key is pressed. I have tried putting a print function to see if it was detected or not and it did not print the message. Could it be something to do with studio?

Script:

local uis = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
local chatting = false
local frame = script.Parent

plr.Chatted:connect(function(msg)
	chatting = false
end)

uis.InputBegan:connect(function(input)
	if input == Enum.KeyCode.Slash and game.StarterGui:GetCoreGuiEnabled("Chat") then
		chatting = true
	elseif input == Enum.KeyCode.Return then
		chatting = false
	end
	
	if chatting == false then		
		if input == Enum.KeyCode.Equals then 
		frame.Visible = not frame.Visible
		end
	end
end)

I am using a localscript btw

3 comments

0

are you using a local script or script if its a script it wont work you have to use local script for input

0

I am using a LocalScript

0

you also need gameProcessed as an argument

2 answers

✓ Accepted answer

Input.KeyCode, not Input. UserInputService.InputBegan gives you an InputObject as an argument.

2 comments

0

also please use :Connect for the love of god

0

Alright lol

You have a little mistake out there on line 11:

 if input == Enum.KeyCode.Slash -- no

if input.KeyCode == Enum.KeyCode.Slash -- yes

you forgot to put keycode there, now it should work..

2 comments

0

oh i was late, damn ok my page did not load

0

Thank you anyways lol

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