Hey there, today I've been messing with keyboard input (using the wiki page as my primary resource). In short, it's not registering input from the Q and E keys when testing as a published place or in the local test server. Works fine when running it with the Play (F5).

I've done some investigating with print()

_G.TileScriptSelected = 1

function onKeyPress(inputObject, gameProcessedEvent)

	if inputObject.KeyCode == Enum.KeyCode.Q then -- I assume this must be the issue...
		print("TEST.") -- ... since THIS print never gets run when Q is pressed
		if _G.TileScriptSelected > 1 then
			_G.TileScriptSelected = _G.TileScriptSelected - 1
			print("Q was pressed: ".._G.TileScriptSelected)
		end
		
	elseif inputObject.KeyCode == Enum.KeyCode.E then -- This never runs either when pressing E
		
		if _G.TileScriptSelected < 10 then
			_G.TileScriptSelected = _G.TileScriptSelected + 1
			print("E was pressed: ".._G.TileScriptSelected)
		end
	end
end

game:GetService("UserInputService").InputBegan:connect(onKeyPress)

I'm pretty stumped. Been at it for a few hours now. Tried it on an entirely fresh map in a localscript and it ran fine. I don't have any other keyboard input scripts that could interfere.

Perhaps I should try the other method on the page - ContextActionService. But I'd like some suggestions of things I could possibly try so I learn more from this.

Thanks a bunch!!!!

2 comments

0

UserInputService is supposed to run in a LocalScript. Since you're using a shared variable you're going to have to use a RemoteEvent or RemoteFunction to change your variable on the server, since it can't cross that boundary.

0

Ah that makes sense! Thanks!