Camera & Delta following issues

Hello!

I am trying to make a drone by using Delta but the drone’s orientation doesn’t want to follow my camera’s orientation.

Script inside of the drone model:

local RS = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
--
local Remote = RS:WaitForChild("DroneMovement")
--    
local Drone = script.Parent
local Movement = Drone.Movement
local FB = Movement.FB
local LR = Movement.LR
local J = Movement.J
local Gyro = Movement.Gyro
--
local MaxTurnRate = 0.5
local MaxSpeed = 25
local MaxSlopeAdjustment = 150
local JumpForce = 500
local JumpLength = 0.1
local Compensation

local CanJump = true
local JumpCooldown = 5

local Drive = 0
--

RunService.Stepped:Connect(function()
    if Drone.PlayerName.Value ~= nil then
        if Movement.Orientation.X > 0 then
            FB.Force = Vector3.new(0, 0,(Drive*(MaxSpeed+(((Movement.Orientation.X/(90/100))/100)*MaxSlopeAdjustment))))
            return Compensation
        elseif Movement.Orientation.X <= 0 then
            FB.Force = Vector3.new(0, 0, (Drive*MaxSpeed))
            return Compensation
        end
    end
end)

--
Remote.OnServerEvent:Connect(function(Player, Var, Decimal)
if Player.Name == Drone.PlayerName.Value then
    if Var == "Mouse" then
        LR.AngularVelocity = Vector3.new(0, (MaxTurnRate*Decimal)*-0.3, 0)

    elseif Var == "Forwards" then
        Drive = -1

    elseif Var == "Reverse" then
        Drive = 1

    elseif Var == "Jump" then
        if CanJump == true then
            CanJump = false
            Gyro.MaxTorque = Vector3.new(40000, 0, 40000)
            J.Force = Vector3.new(0, JumpForce, 0)
            wait(JumpLength)
            J.Force = Vector3.new(0, 0, 0)
            wait(0.5)
            Gyro.MaxTorque = Vector3.new(0, 0, 0)
            wait(JumpCooldown)
            CanJump = true
        end

    elseif Var == "Stop" then
        Drive = 0

    elseif Var == "Destroy" then
        script.Parent:Destroy()
        end
    end
end)

LocalScript inside of the tool:

local RS = game:GetService("ReplicatedStorage")
local Remote = RS:WaitForChild("DroneMovement")
local SpawnDroneRemote = RS:WaitForChild("SpawnDroneRemote")
local ContextActionService = game:GetService("ContextActionService")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local cameraRotation = Vector2.new(0,math.rad(-60))

local players = game:GetService("Players")
local camera = game.Workspace.CurrentCamera
local player = players.LocalPlayer
local character = player.CharacterAdded:Wait()
local torso = character:WaitForChild("UpperTorso")
local default_CameraPosition = torso.Position
local default_CameraZoom = 15
local cameraZoom = default_CameraZoom
local playerPosition = torso.Position

local cameraPosition = default_CameraPosition
--
local Rad = math.rad
--
local RenderSteppedConnection = nil
--
local Player
local Character
local Humanoid
local Mouse
local Camera
local Drone = nil
--
local Tool = script.Parent
--
local ToolEquipped = false
--
local delta = UserInputService:GetMouseDelta()
local function GetDecimalFromMiddle(X)
	local Decimal = ((X-(delta.X/-2)))
return Decimal
end

local function BindControls()
ContextActionService:BindAction("Forwards", function(ActionName, UserInputState, InputObject)
	if UserInputState == Enum.UserInputState.Begin then
		Remote:FireServer("Forwards")
	elseif UserInputState == Enum.UserInputState.End then
		Remote:FireServer("Stop")
	end
end, false, Enum.KeyCode.W)

ContextActionService:BindAction("Reverse", function(ActionName, UserInputState, InputObject)
	if UserInputState == Enum.UserInputState.Begin then
		Remote:FireServer("Reverse")
	elseif UserInputState == Enum.UserInputState.End then
		Remote:FireServer("Stop")
	end
end, false, Enum.KeyCode.S)

ContextActionService:BindAction("Jump", function(ActionName, UserInputState, InputObject)
	if UserInputState == Enum.UserInputState.Begin then
		Remote:FireServer("Jump")
	end
end, false, Enum.KeyCode.Space)

ContextActionService:BindAction("Rotate", function(ActionName, UserInputState, InputObject)
		if UserInputState == Enum.UserInputState.Change then
			
			local rotation = UserInputService:GetMouseDelta()
			cameraRotation = cameraRotation + rotation*math.rad(-0.25)

			local delta = UserInputService:GetMouseDelta()
			local Decimal = (GetDecimalFromMiddle(delta.X))
			Remote:FireServer("Mouse", Decimal)
		end
	end, false, Enum.UserInputType.MouseMovement)
end

local function UnbindControls()
	ContextActionService:UnbindAction("Forwards")
	ContextActionService:UnbindAction("Reverse")
	ContextActionService:UnbindAction("Jump")
	ContextActionService:UnbindAction("Rotate")
end

local function UpdateDroneCamera()
	local cameraRotationCFrame = CFrame.Angles(0, cameraRotation.X, 0)*CFrame.Angles(cameraRotation.Y, 0, 0)
	camera.CFrame = cameraRotationCFrame + Drone.CamPoint.Position + cameraRotationCFrame*Vector3.new(delta.X, 0, 0)
	camera.Focus = camera.CFrame - Vector3.new(0, camera.CFrame.p.Y, 0)
end


local function CheckIfAlive()
	if Character.Humanoid.Health <= 0 then
		return (false)
	elseif Character.Humanoid.Health > 0 then
		return (true)
	end
end

local function ChangeHandleModelTransparency(Transparency)
	local ModelChildren = Tool.DroneModel:GetChildren()
	for i = 1, #ModelChildren do
		ModelChildren[i].Transparency = Transparency
	end
end



--
Tool.Activated:Connect(function()
	if CheckIfAlive() == true then
		if Drone == nil then
			
			RunService:BindToRenderStep("MouseLock",Enum.RenderPriority.Last.Value+1,function()
    			UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
			end)
		
			BindControls()
			Character.HumanoidRootPart.Anchored = true
			Camera.CameraType = Enum.CameraType.Scriptable
			ChangeHandleModelTransparency(1)
			Drone = SpawnDroneRemote:InvokeServer()
			RenderSteppedConnection = RunService.RenderStepped:Connect(function()
				if Drone ~= nil then 
					UpdateDroneCamera()
				end
			end)
			
		elseif Drone ~= nil then
			
			Camera.CameraType = Enum.CameraType.Custom
			UnbindControls()
			Remote:FireServer("Destroy")
			ChangeHandleModelTransparency(0)
			Character.HumanoidRootPart.Anchored = false		
			Drone = nil
			
		end
	end
end)

Tool.Equipped:Connect(function()
	ToolEquipped = true
	Character = Tool.Parent
	Player = game.Players:GetPlayerFromCharacter(Character)
	Humanoid = Character.Humanoid
	Mouse = Player:GetMouse()
	Camera = game.Workspace.CurrentCamera
end)

Tool.Unequipped:Connect(function()
	Camera.CameraType = Enum.CameraType.Custom
	UnbindControls()
	if RenderSteppedConnection then
		RenderSteppedConnection:Disconnect()
	end	
	Character.HumanoidRootPart.Anchored = false
	ToolEquipped = false
	Remote:FireServer("Destroy")
	Player = nil
	Character = nil
	Humanoid = nil
	Mouse = nil
	Camera = nil
end)
 
--local function OnRenderStep()    THIS IS CAUSING THE BIG LAG  ~ Zach <3
   -- local delta = UserInputService:GetMouseDelta()
	--print("The mouse has moved", delta, "since the last step.")
--end
 
--RunService:BindToRenderStep("MeasureMouseMovement", Enum.RenderPriority.Input.Value, OnRenderStep)

local function PlayerChanged()
	local movement = torso.Position - playerPosition
	cameraPosition = cameraPosition + movement
	playerPosition = torso.Position
	UpdateDroneCamera()
end

What the drone looks like currently when you use it (hopefully the video shows):
https://cdn.discordapp.com/attachments/717792337111023657/742144901504041000/2020-08-09_17-13-00.mp4
Workspace:
rr
As you can see the camera moves way ahead of the drone which is a problem, but myself and fellow devs can not solve it, solutions?

1 Like