Hello, I’ve been messing around with client-server connections lately to try to make some cool stuff and I’m having issues with align orientations as a result of this.
I built a small spaceship that uses align orientation to turn, and when the player gets out of the ship I want the ship to tween to a flat orientation but facing the same Y direction it was facing before flight was canceled.
The flight direction I’m handling completely on the client (both linear velocity and align orientation) with the ship’s network ownership being set to the player. I also make it return the last orientation when the player leaves, but for some reason no matter what tween I try it still tweens it to a CFrame angle of 0,0,0.
Here’s the code I’m using:
-- Server
-- // Assets
local base = script.Parent
local controller = script.Controller
local driver = base.VehicleSeat
local ao = base.AlignOrientation
local lv = base.LinearVelocity
local landConnection = nil
local function landVehicle(orientation:CFrame)
local xVal,yVal,zVal = orientation:ToOrientation()
local yValDeg = math.deg(yVal)
lv.VectorVelocity = Vector3.new(0,0,0)
TS:Create(base,TweenInfo.new(1,Enum.EasingStyle.Sine),{CFrame = base.CFrame*CFrame.Angles(0,yValDeg,0)}):Play()
task.wait(1.2)
end
local ui = nil
driver.Changed:Connect(function(mode)
if mode == "Occupant" then
if ui then
local orient = ui.GrabLastOrientation:InvokeClient(ui.Parent.Parent)
ui:Destroy()
ui = nil
base:SetNetworkOwner(nil)
landVehicle(orient)
end
local occ = driver.Occupant
if occ then
local pl = PLRS:GetPlayerFromCharacter(occ.Parent)
if pl then
if landConnection then
landConnection:Disconnect()
landConnection = nil
end
base:SetNetworkOwner(pl)
ui = controller:Clone()
ui.Vehicle.Value = base
ui.Parent = pl.PlayerGui
end
end
end
end)
-- Client
local base = script.Parent.Vehicle.Value
local ao = base.AlignOrientation
local lv = base.LinearVelocity
local driver = base.VehicleSeat
local maxSpeed = 200
local conn
conn = RS.Heartbeat:Connect(function()
ao.CFrame = CFrame.lookAt(base.Position,mouse.Hit.Position)
lv.VectorVelocity = base.CFrame.LookVector*(driver.ThrottleFloat*maxSpeed)
end)
script.Parent.GrabLastOrientation.OnClientInvoke = function()
conn:Disconnect()
task.wait()
return ao.CFrame
end