Cannot walk after jumping off vehicle seat? [Helicopter Chassis Scripting]

Alright so I have a helicopter. That is completely drivable. It works fine just like any other helicopter. But something is not right when I jump off the driveseat. I cannot move or do anything even though I reset!

This has never happened to me before. Its just my first time scripting a helicopter. Doing all the mechanics, driving script stuff and everything. Its my first time doing helicopter chassis scripting stuff. The problem is when I jump off the heli, its weird that I can bearly walk. I cannot walk but can jump. I do not know whats causing the problem in the first place.

I haven’t found any solutions. I’ve been asking people of what’s causing the problem. They don’t know either. For me the it is kinda like a bug or just a straight up a problem. I don’t really know what else to do but create this post.

Here is the full code for the driving script (Its a localscript):

--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 = -2500
		 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 = 2500
		 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, "q")
ContextActionService:BindAction("Up", MoveUp, false, "e")
ContextActionService:BindAction("Left", MoveLeft, false, "a")
ContextActionService:BindAction("Right", MoveRight, false, "d")
ContextActionService:BindAction("Forward", MoveForward, false, "w")
ContextActionService:BindAction("Backwards", MoveBackwards, false, "s")

Heres the normal script code (Detects if player is sitting on seat or not):

--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")
				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()
	end
end)

Its a detector whenever the player sits in the vehicle seat or jumps out of the seat. I detect it using the ChildAdded event connected to function etc etc etc. When the player jumps out the script detects it, it will delete the localscript in playergui. I did that but still, I cannot walk. I clone the localscript and parent it to playergui whenever the script detects a player sitting in the vehicle seat.

I don’t know what am I doing wrong on the scripts. It just doesn’t let me walk when I jump off the vehicle seat.

If you know any ideas of what’s causing the problem? Reply me below. Any suggestions for me to add in the code? Reply below. Know any ways of fixing the problem? Reply :slight_smile:

Thanks in advance. :slight_smile:

2 Likes

I think you have to unbind the context action buttons when the player jumps off the seat. I believe context action service will prioritize the helicopter functions over the control script.

2 Likes

First of all I don’t know about context action service. My friend did the helicopter functions for me and I built the model. I don’t know how contextactionservice works.

UnbindAction is a function of Context Action Service. This will simply unhook the functions you previously associated with certain inputs, and restore the default functions (walking, etc.)

Unbinding a context action can be done like this:

ContextActionService:UnbindAction("Down")
ContextActionService:UnbindAction("Up")
ContextActionService:UnbindAction("Left")
ContextActionService:UnbindAction("Right")
ContextActionService:UnbindAction("Forward")
ContextActionService:UnbindAction("Backwards")

You’ll have to place this somewhere that detects when the player has jumped off the seat.

4 Likes

OH MY GOD! THANK YOU SO MUCH IT FIXED THE PROBLEM!!! THANK YOU VERY MUCH LIFE SAVER!!! I CAN WALK. I’ve been looking for a fix for hours!

2 Likes

I have a question: While trying your code out it appears that the turning isnt correct. I can only drive forward when its 90 degree turned. Is it the same for you?

1 Like

@Paintertable sorry for the late reply but yes it happens the same to me. The turning isnt right. Even the heli is facing 25 degrees it still goes forward and slowing down.