Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to detect which key is pressed only while a character is in a seat?

Asked by 6 years ago

Well basically I need to know this to make custom steering

0
You're gonna need like Enum.KeyCode.A and Enum.KeyCode.D to steer fr2013 88 — 6y

1 answer

Log in to vote
-1
Answered by 6 years ago

Assuming that you're using a LocalScript, Here's your code:

local seat = car.Seat -- change this to your seat

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
mouse.KeyDown:connect(function(key)
if seat:FindFirstChild("SeatWeld") and seat:FindFirstChild("SeatWeld").Part1.Parent.Name == player.Name then
if key == "a" then
-- When the player is sitting and presses a
elseif key == "d" then
-- When the player is sitting and presses d
end
end
end)
mouse.KeyUp:connect(function(key)
if seat:FindFirstChild("SeatWeld") and seat:FindFirstChild("SeatWeld").Part1.Parent.Name == player.Name then
if key == "a" then
-- When the player is sitting and releases a
elseif key == "d" then
-- When the player is sitting and releases d
end
end
end)
0
No. KeyDown and KeyUp are deprecated, never opt to use deprecated methods. The modern alternatives are UserInputService and ContextActionService. SummerEquinox 643 — 6y
0
True. NeonProfile 111 — 6y
0
-1. Code is not indented, makes it harder to read. I can reconsider my downvote once the readability of the code is improved. User#19524 175 — 6y
Ad

Answer this question