Trying to unbind actions, but my character won’t move right.
Local 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 + 5
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 - 5
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 = -5000
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 = 5000
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")
Server:
--Script
local driverseat = script.Parent
local main = script.Parent.Parent.Main
local plane = script.Parent.Parent
local prevOccupant
local localCarScript
driverseat.Changed:connect(function(property)
if property == "Occupant" then
--Sitz ist belegt
if driverseat.Occupant then
--Get the sitting player
local player = game.Players:GetPlayerFromCharacter(driverseat.Occupant.Parent)
if player then
--Sets ownership to player
driverseat:SetNetworkOwner(player)
prevOccupant = player
print(player.Name.." has Networkownership")
localCarScript = script.playerScriptPlane:Clone()
localCarScript.Parent = player.PlayerGui
localCarScript.Obj.Value = plane
wait()
localCarScript.Enabled.Value = true
print("Localscript was inserted")
end
else
driverseat:SetNetworkOwnershipAuto()
script.Parent.Parent.Main.BodyForce.Force = Vector3.new(0, 1, 0)
script.Parent.Parent.Main.BodyVelocity.Velocity = Vector3.new(0, 0, 0)
script.Parent.Parent.Main.BodyVelocity.P = 1250
script.Parent.Parent.Main.BodyVelocity.MaxForce = Vector3.new(4000,4000,4000)
localCarScript:Destroy()
end
end
end)
How can I fix the fact I can’t move my player right?