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

Why doesnt this rotate the car when i press r?

i get no errors on this local script in vehicle seat:

if script.Parent.Occupant == "Humanoid" then

local char = script.Parent.Occupant.Humanoid.Parent

local player = game.Players:GetPlayerFromCharacter(char)

local mouse = player:Getmouse()

mouse.KeyDown:Connect(function(key)

local Key = key.lower("r")

if key == ("r") then

script.Parent.Orientation.X = 0

end

end)

end

1 answer

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 --you can see we're comparing it with an Enum, because that property itself is an Enum

script.Parent.Orientation.X = 0

end

end)

end

3 comments

0

nope keydown works just fine, i use it in other scripts

0

.... it doesnt, i think?

0

try printing some stuff inside the event, to see if it prints or not

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