So I made a UFO got it from toolbox. And its completely drivable and working fine. My friend scripted it for me. I did the functions and he did the drive movements. So get to the point, it is working perfectly fine as intended, you can drive it fly up and down. It works similar to Jailbreak but exactly as Jailbreak.
Alright so I created the airvehicle in an baseplate for testing because I am gonna put it on my game. Which means a different place. So I created this airvehicle thing working fine in the baseplate. But something didn’t go right, when I was playing with the vehicle in the baseplate its fine. I can fly up and down. But when I put it on a different place which is my game, I tried it, I can drive it like turning left and right and moving forward and backwards. And then when I tried to fly it up, It won’t fly no matter what same with fly down. I do not know what’s causing the problem. I just don’t get it, when I fly up and down in the baseplate it works but when I tried it on a different place, it won’t.
I tried seeking help from my friends, but they don’t know what’s causing the problem. I tried searching the solution on some topics and on the internet. But I have no luck of solution. Instead I have to create this topic.
How this airvehicle works?
When I enter the vehicle by walking through the body to the driveseat which means everything in the UFO is not collidable except the driveseat. When I sit, a script detects whenever someone sits and gets out. When I sit, the control script will be cloned and parented to my PlayerGui (the control script is a localscript). When I get off, the localscript inside my PlayerGui which is the control will be destroyed. That’s how my vehicle works, its simple.
Here are codes:
LOCALSCRIPT CODE (Controls Script):
--Localscript
local ContextActionService = game:GetService("ContextActionService")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local plane = script.Obj.Value
local RunService = game:GetService("RunService")
local height = 0
local turn = 0
local moving = 0
local Tilt = 0
local MoveRightKeyDown = false
local MovetLeftKeyDown =false
local vel = plane.Main.BodyVelocity
local tru = plane.Main.BodyForce
local BodyGyro = plane.Main.BodyGyro
local speed = 20
function MoveUp(action_name, action_state)
if action_state == Enum.UserInputState.Begin then
height = 50
end
if action_state == Enum.UserInputState.End then
height = 0
end
end
function MoveDown(action_name, action_state)
if action_state == Enum.UserInputState.Begin then
height = -50
end
if action_state == Enum.UserInputState.End then
height = 0
end
end
function MoveLeft(action_name, action_state)
MovetLeftKeyDown = false
if action_state == Enum.UserInputState.Begin then
MovetLeftKeyDown = true
while MovetLeftKeyDown do
wait(0.1)
turn = turn + 10
end
elseif action_state == Enum.UserInputState.End then
MovetLeftKeyDown = false
end
end
function MoveRight(action_name, action_state)
MoveRightKeyDown = false
if action_state == Enum.UserInputState.Begin then
MoveRightKeyDown = true
while MoveRightKeyDown do
wait(0.1)
turn = turn - 10
end
elseif action_state == Enum.UserInputState.End then
MoveRightKeyDown = false
end
end
function MoveForward(action_name, action_state)
if action_state == Enum.UserInputState.Begin then
moving = -2700
Tilt = -10
end
if action_state == Enum.UserInputState.End then
moving = 0
Tilt = 0
end
end
function MoveBackwards(action_name, action_state)
if action_state == Enum.UserInputState.Begin then
moving = 2700
Tilt = 10
end
if action_state == Enum.UserInputState.End then
moving = 0
Tilt = 0
end
end
RunService:BindToRenderStep("Update", Enum.RenderPriority.Input.Value, function()
BodyGyro.CFrame = CFrame.Angles(0, math.rad(turn), 0) * CFrame.Angles(math.rad(Tilt), 0, 0)
tru.Force = plane.Main.CFrame.LookVector * (-moving * 2 )
vel.Velocity = Vector3.new(0,height,0)
end)
ContextActionService:BindAction("Down", MoveDown, false, Enum.KeyCode.Q)
ContextActionService:BindAction("Up", MoveUp, false, Enum.KeyCode.E)
ContextActionService:BindAction("Left", MoveLeft, false, Enum.KeyCode.A)
ContextActionService:BindAction("Right", MoveRight, false, Enum.KeyCode.D)
ContextActionService:BindAction("Forward", MoveForward, false, Enum.KeyCode.W)
ContextActionService:BindAction("Backwards", MoveBackwards, false, Enum.KeyCode.S)
plane.DriverSeat.ChildRemoved:Connect(function(child)
if child.Name == "SeatWeld" and child:IsA("Weld") then
ContextActionService:UnbindAction("Down")
ContextActionService:UnbindAction("Up")
ContextActionService:UnbindAction("Left")
ContextActionService:UnbindAction("Right")
ContextActionService:UnbindAction("Forward")
ContextActionService:UnbindAction("Backwards")
end
end)
NORMAL SCRIPT CODE (Detects when player sits or gets off the vehicle):
--Script
local driverseat = script.Parent
local main = script.Parent.Parent.Main
local plane = script.Parent.Parent
driverseat.ChildAdded:connect(function(child)
if child.Name == "SeatWeld" and child:IsA("Weld") then
--Sitz ist belegt
if child then
--Get the sitting player
player = game.Players:GetPlayerFromCharacter(child.Part1.Parent)
if player then
--Sets ownership to player
--driverseat:SetNetworkOwner(player)
--print(player.Name.." has Networkownership")
driverseat.DoorOpen:Play()
driverseat.DoorOpen.Ended:Wait()
driverseat.DoorClose:Play()
driverseat.DoorClose.Ended:Wait()
wait()
script.Parent.Parent.Body.Body.Running:Play()
for i = 1,100 do
script.Parent.Parent.Body.Body.Running.PlaybackSpeed = script.Parent.Parent.Body.Body.Running.PlaybackSpeed + .01
wait()
end
local localCarScript = script.HelicopterChassis:Clone()
localCarScript.Parent = player.PlayerGui
localCarScript.Obj.Value = plane
print("Localscript was inserted")
end
end
end
end)
driverseat.ChildRemoved:Connect(function(child)
if child.Name == "SeatWeld" and child:IsA("Weld") then
print("Localscript deleted...")
player.PlayerGui:WaitForChild("HelicopterChassis"):Destroy()
wait()
script.Parent.Parent.Body.Body.Running:Play()
for i = 1,100 do
script.Parent.Parent.Body.Body.Running.PlaybackSpeed = script.Parent.Parent.Body.Body.Running.PlaybackSpeed - .01
wait()
end
script.Parent.Parent.Body.Body.Running:Stop()
end
end)
That’s the full code! However, I do not know what I am doing wrong in the entire code. I use ContextActionService for the hotkeys. You know, they buttons what make the airvehicle work.
Example:
ContextActionService:BindAction("Forward", MoveForward, false, "w") -- MoveForward is a function just without ()
If you got any suggestions to fix this problem? Let me know down in the replies. Got ideas? Suggest it to me. You have something to add in my code? Reply me
Thanks in advance!