This is my very first post so I tried my best to try and make the scripts input-able but it looks by the preview it got split.
-
What do you want to achieve?
I’m making a spaceflight system -
What is the issue?
Although it does work, unless I get it practically frame perfect I can never do two buttons at once. ex: if I wanted to turn another direction while flying I would need to stop moving first, then turn, and finally start moving -
What solutions have you tried so far?
I’ve been looking all over the Dev Hub and have tried making it so it is it’s own button esc so when I press two buttons it’s one command.
Videos showing spaceflight system
The Scripts were from the Western Template Horse Carriage at first (i dont think the western template exists anymore) and I got rid of it’s normal Vector2 movement entirely and replaced it with Lookvector movement aswell as modifying it so it went off of land too (because before if you tried to run off the map you would just be stopped by the second script.
This is one of the two scripts
CarScript (server)
local car = script.Parent
car.DriveSeat.Changed:Connect(function(property)
local occupant = car:WaitForChild(“DriveSeat”).Occupantif occupant == nil then
car.DriveSeat.Anchored = true
else
if occupant.Seated then
if car.DriveSeat.Anchored == true then
car.DriveSeat.Anchored = false
print(“dw, you safe now boss”)
end
else
print(“no work”)
end
end
end)car.DriveSeat.Changed:connect(function(property)
if property == “Occupant” then
if car:WaitForChild(“DriveSeat”).Occupant then
local player = game.Players:GetPlayerFromCharacter(car.DriveSeat.Occupant.Parent)
if player then
task.wait(.1)
car.DriveSeat:SetNetworkOwner(player)
print(“bloop”)
local localCarScript = script.LocalCarScript:Clone()
localCarScript.Parent = player.PlayerGui
localCarScript.Car.Value = car
localCarScript.Disabled = false
end
end
end
end)spawn(function()
while true do
game:GetService(“RunService”).Stepped:wait()
for i, model in pairs(car:GetChildren()) do
if model:FindFirstChild(“Humanoid”) then
if car.DriveSeat.Occupant then
model.Humanoid.PlatformStand = true
else
model.Humanoid.PlatformStand = false
end
end
end
end
end)
The Local Script inside of it: LocalCarScript (and inside of that is ObjectValue called Car)
local camera = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer
local character = player.Character
local humanoidRootPart = character.HumanoidRootPart
local car = script:WaitForChild(“Car”).Value
local stats = car:WaitForChild(“Configurations”)local movement = Vector2.new(0, 0)
local pressed = false
local on = falsecar.StartEngine.ClickDetector.MouseClick:Connect(function()
if on == false then
on = true
print(“on”)-- Input begin game:GetService("UserInputService").InputBegan:Connect(function(inputObject, gameProcessedEvent) if not gameProcessedEvent then if inputObject.KeyCode == Enum.KeyCode.W or inputObject.KeyCode == Enum.KeyCode.P then if not pressed then pressed = true repeat wait() car.Chassis.CFrame = car.Chassis.CFrame * CFrame.new(0, 0, -5) task.wait(.001) local cf = car.Chassis.CFrame local lv = cf.lookVector car.Chassis.CFrame = cf + (lv * Vector3.new(0, 0, 0)) print("forward") until not pressed end elseif inputObject.KeyCode == Enum.KeyCode.A then if not pressed then pressed = true repeat wait() car.Chassis.CFrame = car.Chassis.CFrame * CFrame.Angles(0, .1, 0) task.wait(.001) local cf = car.Chassis.CFrame local lv = cf.lookVector car.Chassis.CFrame = cf + (lv * Vector3.new(0, 0, 0)) print("rotate a") until not pressed end elseif inputObject.KeyCode == Enum.KeyCode.S then if not pressed then pressed = true repeat wait() car.Chassis.CFrame = car.Chassis.CFrame * CFrame.new(0, 0, 5) task.wait(.001) local cf = car.Chassis.CFrame local lv = cf.lookVector car.Chassis.CFrame = cf + (lv * Vector3.new(0, 0, 0)) print("back") until not pressed end elseif inputObject.KeyCode == Enum.KeyCode.D then if not pressed then pressed = true repeat wait() car.Chassis.CFrame = car.Chassis.CFrame * CFrame.Angles(0, -.1, 0) task.wait(.001) local cf = car.Chassis.CFrame local lv = cf.lookVector car.Chassis.CFrame = cf + (lv * Vector3.new(0, 0, 0)) print("rotate d") until not pressed end elseif inputObject.KeyCode == Enum.KeyCode.Q then if not pressed then pressed = true repeat wait() car.Chassis.CFrame = car.Chassis.CFrame * CFrame.new(0, 5, 0) task.wait(.001) local cf = car.Chassis.CFrame local lv = cf.lookVector car.Chassis.CFrame = cf + (lv * Vector3.new(0, 0, 0)) until not pressed end elseif inputObject.KeyCode == Enum.KeyCode.E then if not pressed then pressed = true repeat wait() car.Chassis.CFrame = car.Chassis.CFrame * CFrame.new(0, -5, 0) task.wait(.001) local cf = car.Chassis.CFrame local lv = cf.lookVector car.Chassis.CFrame = cf + (lv * Vector3.new(0, 0, 0)) until not pressed end end end end) -- Input end game:GetService("UserInputService").InputEnded:connect(function(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.W then pressed = false elseif inputObject.KeyCode == Enum.KeyCode.A then pressed = false elseif inputObject.KeyCode == Enum.KeyCode.S then pressed = false elseif inputObject.KeyCode == Enum.KeyCode.D then pressed = false elseif inputObject.KeyCode == Enum.KeyCode.Q then pressed = false elseif inputObject.KeyCode == Enum.KeyCode.E then pressed = false end end) local force = 0 local damping = 0 local mass = 0 for i, v in pairs(car:GetChildren()) do if v:IsA("BasePart") then mass = mass + (v:GetMass() * 196.2) end end force = mass * stats.Suspension.Value damping = force / stats.Bounce.Value local bodyVelocity = Instance.new("BodyVelocity", car.Chassis) bodyVelocity.velocity = Vector3.new(0, 0, 0) bodyVelocity.maxForce = Vector3.new(0, 0, 0) local bodyAngularVelocity = Instance.new("BodyAngularVelocity", car.Chassis) bodyAngularVelocity.angularvelocity = Vector3.new(0, 0, 0) bodyAngularVelocity.maxTorque = Vector3.new(0, 0, 0) local rotation = 0 local function UpdateThruster(thruster) --Make sure we have a bodythrust to move the wheel local bodyThrust = thruster:FindFirstChild("BodyThrust") if not bodyThrust then bodyThrust = Instance.new("BodyThrust", thruster) end --Do some raycasting to get the height of the wheel local ray = Ray.new(thruster.Position, thruster.CFrame:vectorToWorldSpace(Vector3.new(0, -1, 0)) * stats.Height.Value) local hit, position = game.Workspace:FindPartOnRay(ray, car) local thrusterHeight = (position - thruster.Position).magnitude if hit and hit.CanCollide then --If we're on the ground, apply some forces to push the wheel up bodyThrust.force = Vector3.new(0, ((stats.Height.Value - thrusterHeight)^2) * (force / stats.Height.Value^2), 0) local thrusterDamping = thruster.CFrame:toObjectSpace(CFrame.new(thruster.Velocity + thruster.Position)).p * damping bodyThrust.force = bodyThrust.force - Vector3.new(0, thrusterDamping.Y, 0) else bodyThrust.force = Vector3.new(0, 0, 0) end --Wheels
–[[local wheelWeld = thruster:FindFirstChild(“WheelWeld”)
if wheelWeld then
wheelWeld.C0 = CFrame.new(0, -math.min(thrusterHeight, stats.Height.Value * 0.8) + (wheelWeld.Part1.Size.Y / 2), 0)
– Wheel turning
local offset = car.Chassis.CFrame:inverse() * thruster.CFrame
local speed = car.Chassis.CFrame:vectorToObjectSpace(car.Chassis.Velocity)
if offset.Z < 0 then
local direction = 1
if speed.Z > 0 then
direction = -1
end
wheelWeld.C0 = wheelWeld.C0 * CFrame.Angles(0, (car.Chassis.RotVelocity.Y / 2) * direction, 0)
end
wheelWeld.C0 = wheelWeld.C0 * CFrame.Angles(rotation, 0, 0)
end]]
end--A simple function to check if the car is grounded local function IsGrounded() local ray = Ray.new((car.Chassis.CFrame * CFrame.new(0, 0, (car.Chassis.Size.Z / 2) - 1)).p, car.Chassis.CFrame:vectorToWorldSpace(Vector3.new(0, -1, 0)) * (stats.Height.Value + 0.2)) local hit, position = game.Workspace:FindPartOnRay(ray, car) if hit and hit.CanCollide then return true end return true end camera.CameraType = Enum.CameraType.Follow spawn(function() while character.Humanoid.SeatPart == car.DriveSeat do game:GetService("RunService").RenderStepped:wait() if IsGrounded() then if movement.Y ~= 0 then local velocity = humanoidRootPart.CFrame.lookVector * movement.Y * stats.Speed.Value humanoidRootPart.Velocity = humanoidRootPart.Velocity:Lerp(velocity, 0.4) bodyVelocity.maxForce = Vector3.new(0, 0, 0) else bodyVelocity.maxForce = Vector3.new(mass / 2, mass / 4, mass / 2) end local rotVelocity = humanoidRootPart.CFrame:vectorToWorldSpace(Vector3.new(movement.Y * stats.Speed.Value / 50, 0, -humanoidRootPart.RotVelocity.Y * 5 * movement.Y)) local speed = -humanoidRootPart.CFrame:vectorToObjectSpace(humanoidRootPart.Velocity).unit.Z rotation = rotation + math.rad((-stats.Speed.Value / 5) * movement.Y) if math.abs(speed) > 0.1 then rotVelocity = rotVelocity + humanoidRootPart.CFrame:vectorToWorldSpace((Vector3.new(0, -movement.X * speed * stats.TurnSpeed.Value, 0))) bodyAngularVelocity.maxTorque = Vector3.new(0, 0, 0) else bodyAngularVelocity.maxTorque = Vector3.new(mass / 4, mass / 2, mass / 4) end humanoidRootPart.RotVelocity = humanoidRootPart.RotVelocity:Lerp(rotVelocity, 0.1) --bodyVelocity.maxForce = Vector3.new(mass / 3, mass / 6, mass / 3) --bodyAngularVelocity.maxTorque = Vector3.new(mass / 6, mass / 3, mass / 6) else bodyVelocity.maxForce = Vector3.new(0, 0, 0) bodyAngularVelocity.maxTorque = Vector3.new(0, 0, 0) end for i, part in pairs(car:GetChildren()) do if part.Name == "Thruster" then UpdateThruster(part) end end end for i, v in pairs(car:GetChildren()) do if v:FindFirstChild("BodyThrust") then v.BodyThrust:Destroy() end end bodyVelocity:Destroy() bodyAngularVelocity:Destroy() camera.CameraType = Enum.CameraType.Custom script:Destroy() end)
else
local newver = script:Clone()
newver.Parent = script.Parent
script:Destroy()
endend)
–PROXIMITY STARTENGINE
car.StartEngine.ProximityPrompt.Triggered:Connect(function()
if on == false then
on = true
print(“on”)-- Input begin game:GetService("UserInputService").InputBegan:Connect(function(inputObject, gameProcessedEvent) if not gameProcessedEvent then if inputObject.KeyCode == Enum.KeyCode.W or inputObject.KeyCode == Enum.KeyCode.P then if not pressed then pressed = true repeat wait() car.Chassis.CFrame = car.Chassis.CFrame * CFrame.new(0, 0, -5) task.wait(.001) local cf = car.Chassis.CFrame local lv = cf.lookVector car.Chassis.CFrame = cf + (lv * Vector3.new(0, 0, 0)) print("forward") until not pressed end elseif inputObject.KeyCode == Enum.KeyCode.A then if not pressed then pressed = true repeat wait() car.Chassis.CFrame = car.Chassis.CFrame * CFrame.Angles(0, .1, 0) task.wait(.001) local cf = car.Chassis.CFrame local lv = cf.lookVector car.Chassis.CFrame = cf + (lv * Vector3.new(0, 0, 0)) print("rotate a") until not pressed end elseif inputObject.KeyCode == Enum.KeyCode.S then if not pressed then pressed = true repeat wait() car.Chassis.CFrame = car.Chassis.CFrame * CFrame.new(0, 0, 5) task.wait(.001) local cf = car.Chassis.CFrame local lv = cf.lookVector car.Chassis.CFrame = cf + (lv * Vector3.new(0, 0, 0)) print("back") until not pressed end elseif inputObject.KeyCode == Enum.KeyCode.D then if not pressed then pressed = true repeat wait() car.Chassis.CFrame = car.Chassis.CFrame * CFrame.Angles(0, -.1, 0) task.wait(.001) local cf = car.Chassis.CFrame local lv = cf.lookVector car.Chassis.CFrame = cf + (lv * Vector3.new(0, 0, 0)) print("rotate d") until not pressed end elseif inputObject.KeyCode == Enum.KeyCode.Q then if not pressed then pressed = true repeat wait() car.Chassis.CFrame = car.Chassis.CFrame * CFrame.new(0, 5, 0) task.wait(.001) local cf = car.Chassis.CFrame local lv = cf.lookVector car.Chassis.CFrame = cf + (lv * Vector3.new(0, 0, 0)) until not pressed end elseif inputObject.KeyCode == Enum.KeyCode.E then if not pressed then pressed = true repeat wait() car.Chassis.CFrame = car.Chassis.CFrame * CFrame.new(0, -5, 0) task.wait(.001) local cf = car.Chassis.CFrame local lv = cf.lookVector car.Chassis.CFrame = cf + (lv * Vector3.new(0, 0, 0)) until not pressed end end end end) -- Input end game:GetService("UserInputService").InputEnded:connect(function(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.W then pressed = false elseif inputObject.KeyCode == Enum.KeyCode.A then pressed = false elseif inputObject.KeyCode == Enum.KeyCode.S then pressed = false elseif inputObject.KeyCode == Enum.KeyCode.D then pressed = false elseif inputObject.KeyCode == Enum.KeyCode.Q then pressed = false elseif inputObject.KeyCode == Enum.KeyCode.E then pressed = false end end) local force = 0 local damping = 0 local mass = 0 for i, v in pairs(car:GetChildren()) do if v:IsA("BasePart") then mass = mass + (v:GetMass() * 196.2) end end force = mass * stats.Suspension.Value damping = force / stats.Bounce.Value local bodyVelocity = Instance.new("BodyVelocity", car.Chassis) bodyVelocity.velocity = Vector3.new(0, 0, 0) bodyVelocity.maxForce = Vector3.new(0, 0, 0) local bodyAngularVelocity = Instance.new("BodyAngularVelocity", car.Chassis) bodyAngularVelocity.angularvelocity = Vector3.new(0, 0, 0) bodyAngularVelocity.maxTorque = Vector3.new(0, 0, 0) local rotation = 0 local function UpdateThruster(thruster) --Make sure we have a bodythrust to move the wheel local bodyThrust = thruster:FindFirstChild("BodyThrust") if not bodyThrust then bodyThrust = Instance.new("BodyThrust", thruster) end --Do some raycasting to get the height of the wheel local ray = Ray.new(thruster.Position, thruster.CFrame:vectorToWorldSpace(Vector3.new(0, -1, 0)) * stats.Height.Value) local hit, position = game.Workspace:FindPartOnRay(ray, car) local thrusterHeight = (position - thruster.Position).magnitude if hit and hit.CanCollide then --If we're on the ground, apply some forces to push the wheel up bodyThrust.force = Vector3.new(0, ((stats.Height.Value - thrusterHeight)^2) * (force / stats.Height.Value^2), 0) local thrusterDamping = thruster.CFrame:toObjectSpace(CFrame.new(thruster.Velocity + thruster.Position)).p * damping bodyThrust.force = bodyThrust.force - Vector3.new(0, thrusterDamping.Y, 0) else bodyThrust.force = Vector3.new(0, 0, 0) end --Wheels
–[[local wheelWeld = thruster:FindFirstChild(“WheelWeld”)
if wheelWeld then
wheelWeld.C0 = CFrame.new(0, -math.min(thrusterHeight, stats.Height.Value * 0.8) + (wheelWeld.Part1.Size.Y / 2), 0)
– Wheel turning
local offset = car.Chassis.CFrame:inverse() * thruster.CFrame
local speed = car.Chassis.CFrame:vectorToObjectSpace(car.Chassis.Velocity)
if offset.Z < 0 then
local direction = 1
if speed.Z > 0 then
direction = -1
end
wheelWeld.C0 = wheelWeld.C0 * CFrame.Angles(0, (car.Chassis.RotVelocity.Y / 2) * direction, 0)
end
wheelWeld.C0 = wheelWeld.C0 * CFrame.Angles(rotation, 0, 0)
end]]
end--A simple function to check if the car is grounded local function IsGrounded() local ray = Ray.new((car.Chassis.CFrame * CFrame.new(0, 0, (car.Chassis.Size.Z / 2) - 1)).p, car.Chassis.CFrame:vectorToWorldSpace(Vector3.new(0, -1, 0)) * (stats.Height.Value + 0.2)) local hit, position = game.Workspace:FindPartOnRay(ray, car) if hit and hit.CanCollide then return true end return true end camera.CameraType = Enum.CameraType.Follow spawn(function() while character.Humanoid.SeatPart == car.DriveSeat do game:GetService("RunService").RenderStepped:wait() if IsGrounded() then if movement.Y ~= 0 then local velocity = humanoidRootPart.CFrame.lookVector * movement.Y * stats.Speed.Value humanoidRootPart.Velocity = humanoidRootPart.Velocity:Lerp(velocity, 0.4) bodyVelocity.maxForce = Vector3.new(0, 0, 0) else bodyVelocity.maxForce = Vector3.new(mass / 2, mass / 4, mass / 2) end local rotVelocity = humanoidRootPart.CFrame:vectorToWorldSpace(Vector3.new(movement.Y * stats.Speed.Value / 50, 0, -humanoidRootPart.RotVelocity.Y * 5 * movement.Y)) local speed = -humanoidRootPart.CFrame:vectorToObjectSpace(humanoidRootPart.Velocity).unit.Z rotation = rotation + math.rad((-stats.Speed.Value / 5) * movement.Y) if math.abs(speed) > 0.1 then rotVelocity = rotVelocity + humanoidRootPart.CFrame:vectorToWorldSpace((Vector3.new(0, -movement.X * speed * stats.TurnSpeed.Value, 0))) bodyAngularVelocity.maxTorque = Vector3.new(0, 0, 0) else bodyAngularVelocity.maxTorque = Vector3.new(mass / 4, mass / 2, mass / 4) end humanoidRootPart.RotVelocity = humanoidRootPart.RotVelocity:Lerp(rotVelocity, 0.1) --bodyVelocity.maxForce = Vector3.new(mass / 3, mass / 6, mass / 3) --bodyAngularVelocity.maxTorque = Vector3.new(mass / 6, mass / 3, mass / 6) else bodyVelocity.maxForce = Vector3.new(0, 0, 0) bodyAngularVelocity.maxTorque = Vector3.new(0, 0, 0) end for i, part in pairs(car:GetChildren()) do if part.Name == "Thruster" then UpdateThruster(part) end end end for i, v in pairs(car:GetChildren()) do if v:FindFirstChild("BodyThrust") then v.BodyThrust:Destroy() end end bodyVelocity:Destroy() bodyAngularVelocity:Destroy() camera.CameraType = Enum.CameraType.Custom script:Destroy() end)
else
local newver = script:Clone()
newver.Parent = script.Parent
script:Destroy()
endend)
can anyone help me with this problem of it not letting me use multiple inputs at once?