I’m trying to make a plane and I’ve ran into an extremely strange issue. It seems like when I first sit in the plane it moves for the client, but not the server even though all of the movement is handled on the server. This is my LocalScript code:
-- Runs when the player sits in an airplane
game:GetService("RunService").RenderStepped:connect(function()
camera.CFrame = player.Character.HumanoidRootPart.CFrame * offset
local mousePos = userInputService:GetMouseLocation()
local unitRay = workspace.CurrentCamera:ViewportPointToRay(mousePos.X, mousePos.Y)
local xOffset, yOffset = getoffset()
game.ReplicatedStorage.tiltPlane:FireServer(unitRay.Origin, unitRay.Direction, xOffset, yOffset)
end)
This is my server script:
game.ReplicatedStorage.tiltPlane.OnServerEvent:Connect(function(player, Origin, Direction, xOffset, yOffset)
local seat = player.Character.Humanoid.SeatPart
if seat == nil then return end
local model = seat.Parent
local plane = getPlane(model)
local mouseHitP = Origin + Direction * 100
plane.model.PrimaryPart.BodyGyro.CFrame = CFrame.lookAt(plane.model.PrimaryPart.Position, Vector3.new(mouseHitP.X,mouseHitP.Y,mouseHitP.Z))
plane.model.PrimaryPart.BodyGyro.CFrame *= CFrame.Angles(0,0,math.rad(xOffset))
plane.model.PrimaryPart.BodyVelocity.Velocity = plane.model.PrimaryPart.CFrame.LookVector * plane.Throttle
end)
It basically just grabs what plane the player is sitting in and then applys velocity and orientation to the BodyVelocity and BodyGyro. All pretty simple stuff that shouldn’t cause any issues. But this is what it looks like on the client:
The BodyVelocity is supposed to apply velocity in the direction of the lookVector but it doesn’t do that for the first few seconds and then correctly applies the velocity afterward. Now here is what it looks like on the server:
For some reason the plane stays hovering in the air for a few seconds and then corrects itself. This is why the BodyVelocity isn’t being applied correctly on the client. This is extremely strange because all of the changes to the BodyVelocity and BodyGyro is handled on the server and not the client but it’s replicating to the client and not the server for the first few seconds. I’ve had this issue since I first started creating this plane even when completely rewriting how the plane works. Any help would be greatly appreciated!