Why won't this KeyCode function work?

Why wont’ this Keycode script work?

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(input)
	if input.Keycode == Enum.KeyCode.W then
		print("YAY")
	end
end)

You misspelled Keycode, Its KeyCode

(Lua gotta be like that for some reason)

2 Likes

since he wrote KeyCode wrong, well, apart from that, whatever he does, don’t use “W” as a key letter if you want to know how to know if the character runs, use more or less run service or the Humanoid of the character but don’t use W

It still won’t print the message for some reason:

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.E then
		print('Cool')
	end
end)

Questions:

  • Is it a LocalScript?

  • Where is it Located?

  • Is there code yielding above this code?

It’s a regular script, and it’s in the workspace.

Its Supposed to be within StarterPlayerScripts just so you know.

Oh my gosh thank you so much, but how can I make it so it works in a regular script in a model?

I don’t think you are able to, There might be a way but i’m not aware of it, Its better to handle this kind of stuff on the Client as it is much easier.

Please explain exactly what are you trying to do.

Is it in a Part so you can only press the key there?

Is it something similar to a ProximityPrompt in the ProximetyPromptService?
There’s a tutorial for that as well.
Is it to control something?

The more information we have the better chance someone will know exactly how to help you out.

I was trying to make a helicopter that was controlled by the keys, which would change the body’s velocity.

So use a VehicleSeat to get the WASD key inputs. Simple and easy since that’s what it’s designed for.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.