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

E Key isnt printing "hi". Help please?

Heres my code:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

mouse.KeyDown:connect(function(key)
	if key == "e" then
		print("hi")
    end
end)

Isn't working and im trying to find out whats wrong (Nothing is printing in output)

1 answer

✓ Accepted answer

It is suggested that you use ROBLOX's newer form of Input by UserInputService. Make sure that this is being done by a LocalScript & make sure that the LocalScript is in the proper directory (StarterPlayer.StarterCharacterScripts or StarterPlayer.StarterPlayerScripts or StarterGear or StarterGui)

You can learn about UserInputService here: https://developer.roblox.com/en-us/api-reference/class/UserInputService

game:GetService("UserInputService").InputBegan:Connect(function(InputObject,GameProcessedEvent)
	if GameProcessedEvent then
		return
	end
	if InputObject.KeyCode == Enum.KeyCode.E then
		print("E has been pressed!")
	end
end)

while true do
	wait()
	if game:GetService("UserInputService"):IsKeyDown(Enum.KeyCode.E) then
		print("E is being held down!")
	end
end

2 comments

0

But how do I make it so I can hold it down and it will print

0

I've made a second edit so that you can see how.

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