So, I am making a plane script ( I started 1 hour ago ) and its going well, except the fact that when I test it online it lags. Now, I am aware that scripts run slower on their servers than in studio but is there a way of getting around this lag?
Here's the localscript that rotates the plane, ect:
local plr = game.Players.LocalPlayer
local m = plr:GetMouse()
local run = game:GetService("RunService")
local cam = workspace.CurrentCamera
local user = game:GetService("UserInputService")
local CurrentSpeed = 30
local CurrentMass = 0
local x,y = 0,0
function GetBankAngle(M)
local VSX,X = M.ViewSizeX,M.X
local Ratio = (((VSX / 2) - X)/(VSX / 2))
Ratio = (Ratio < -1 and -1 or Ratio > 1 and 1 or Ratio)
return math.rad(Ratio * 90)
end
onchar = function(char)
local plane = game.ReplicatedStorage:WaitForChild("Plane"):Clone()
plane.Parent = workspace.Planes
local function GetPlaneMass()
local m = 0
local function Scan(p)
for _,o in pairs(p:GetChildren()) do
if (o:IsA("BasePart")) then m = (m+o:GetMass()) end
Scan(o)
end
end
Scan(plane)
CurrentMass = m
return m
end
cam.CameraSubject = plane.Stats
m.TargetFilter = nil
char.Parent = nil
plane:MoveTo(Vector3.new(math.random(-200,200),100,math.random(-200,200)))
print("GOT THIS FAR OYE22")
local turn,force = game.ReplicatedStorage.Setup:InvokeServer(plane)
--plane.Propellar:InvokeServer(true)
print("GOT THIS FAR OYE")
user.InputChanged:connect(function(obj)
if obj.UserInputType == Enum.UserInputType.MouseMovement then
x = obj.Delta.x
y = obj.Delta.y
end
end)
wait(1)
local update = run.RenderStepped:connect(function()
print(update)
local dir = m.Hit.p
local mass = plane.HumanoidRootPart:GetMass()
--[[for _,v in pairs(plane:GetChildren()) do
if v:IsA("BasePart") or v:IsA("UnionOperation") then
mass = mass+v:GetMass()
end
end--]]
force.Velocity = (plane.HumanoidRootPart.CFrame.lookVector*CurrentSpeed)
turn.CFrame = CFrame.new(plane.HumanoidRootPart.CFrame.p,dir)*CFrame.Angles(math.rad(x/16),math.rad(y/16),0) *CFrame.Angles(0,0, GetBankAngle(m))
end)
end
onchar(plr.Character)
plr.CharacterAdded:connect(onchar)
