KeyDown is a deprecated event, it doesn't work. You would have to use UserInputService and exaclty the event of that service called InputBegan.
Very cool link.
game:GetService("UserInputService").InputBegan:Connect(input)
--you see, the main paramater for this is the "input" (there is also a second paramater but its pretty complicated check it out in the given link), an input is an InputObject class and that is essantially the input that just got detected, it can be a mouse, a keyboard key, the keyboard itself, a lot og things, check this class out it has really interesting stuff. Anyways, an InputObject has a property called .KeyCode, which is the keycode of the input object that got detected, and an inputobject will have a .KeyCode if it was a key of course
if you pressed A the keycode will be A, it's an Enum.
print(input) --this would just print the input instance, which is InputObject, so you would never use that.
print(inpit.KeyCode) --this would press the key
end)
Now let's use that here.
if script.Parent.Occupant == "Humanoid" then
local char = script.Parent.Occupant.Humanoid.Parent
local player = game.Players:GetPlayerFromCharacter(char)
local mouse = player:Getmouse()
game:GetService("UserInputService").InputBegan:Connect(input)
local Key = input.KeyCode
if key == Enum.KeyCode.R then
script.Parent.Orientation.X = 0
end
end)
end
3 comments
nope keydown works just fine, i use it in other scripts
.... it doesnt, i think?
try printing some stuff inside the event, to see if it prints or not