This is the most important part of the local script:
--E
uis.InputEnded:Connect(function(key)
if key.KeyCode == Enum.KeyCode.E then
vel.Velocity = Vector3.new(0,0,0)
end
end)
uis.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.E then
vel.Velocity = Vector3.new(0,10,0)
end
end)
--Q
uis.InputEnded:Connect(function(key)
if key.KeyCode == Enum.KeyCode.Q then
vel.Velocity = Vector3.new(0,0,0)
end
end)
uis.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.Q then
vel.Velocity = Vector3.new(0,-10,0)
end
end)
--W
uis.InputEnded:Connect(function(key)
if key.KeyCode == Enum.KeyCode.W then
vel.Velocity = Vector3.new(0,0,0)
end
end)
uis.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.W then
vel.Velocity = engine.CFrame.LookVector * 10
end
end)
--S
uis.InputEnded:Connect(function(key)
if key.KeyCode == Enum.KeyCode.S then
vel.Velocity = Vector3.new(0,0,0)
end
end)
uis.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.S then
vel.Velocity = engine.CFrame.LookVector * -10
end
end)
How would i go about making A and D ones which turn the engine left and right?
Bonus points if you can point out a way to make this script more efficient and less clunky
You are creating a separate connection for each key. I would consider that extremely inefficient. Just condense it into a single connection.
example:
uis.InputBegan:Connect(function(key)
if key.Keycode == Enum.Keycode.S then
--code here
elseif key.Keycode == Enum.Keycode.W then
--code here
--more elseif statements here for more keys.
end)
yes, if this doesnt make sense:
E is to move the vehicle up
Q is to move the vehicle up
W is to move the vehicle forwards
S is to move the vehicle backwards
A is to turn the vehicle left
D is to turn the vehicle right
I have never worked with something like this, so its unlikely that any suggestion that I give would be very efficient or even work for that matter.
So, I will just link the documentation, which you can look through. The solution may be somewhere in there.
Link to the documentation for BodyMovers(deprecated and not suggested to be used anymore)
Link to the documentation for the BodyMovers replacement: