Reducing Server Script Lag

How would I go about executing a local script for the client meanwhile also executing said script in a server script so its still replicated to the server, My goal is to reduce Client Side Lag while still keep server replication

This script is for a car

Local Script:

local User = game.Players.LocalPlayer
local UserBody = User.Character
local Model = script.Object.Value
local LeftHand = script.LeftHand.Value
local RightHand = script.RightHand.Value
local WaistAngle = math.rad(20) -- Back Forward Angle
local NeckAngle = math.rad(-15) -- Neck Forward Angle
local Stepped
---Create Welds identical to Motor6Ds to override animations
function ConfigureJoints()
local RightShoulder = UserBody:WaitForChild("RightUpperArm").RightShoulder
local LeftShoulder = UserBody:WaitForChild("LeftUpperArm").LeftShoulder
local RightElbow = UserBody.RightLowerArm.RightElbow
local LeftElbow = UserBody.LeftLowerArm.LeftElbow
--Torso Weld is to keep the player leaning forward so the arms reach the steering wheel
local TorsoWeld = Instance.new("Weld")
TorsoWeld.Part0 = UserBody.UpperTorso.Waist.Part0
TorsoWeld.Part1 = UserBody.UpperTorso.Waist.Part1
TorsoWeld.C0 = UserBody.UpperTorso.Waist.C0 *CFrame.Angles(-WaistAngle, 0, 0)
TorsoWeld.C1 = UserBody.UpperTorso.Waist.C1
TorsoWeld.Name = "WaistWeld"
TorsoWeld.Parent = UserBody.UpperTorso
--Neck weld is to make the player's head look up, since the UserBodyacter is leaning forward the head is naturally looking down, so we need to adjust
local NeckWeld = Instance.new("Weld")
NeckWeld.Part0 = UserBody.Head.Neck.Part0
NeckWeld.Part1 = UserBody.Head.Neck.Part1
NeckWeld.C0 = UserBody.Head.Neck.C0 *CFrame.Angles(-NeckAngle, 0, 0)
NeckWeld.C1 = UserBody.Head.Neck.C1
NeckWeld.Name = "NeckWeld"
NeckWeld.Parent = UserBody.Head
--Shoulder welds so we can make them move towards the steering wheel
local RightShoulderWeld = Instance.new("Weld")
RightShoulderWeld.Part0 = RightShoulder.Part0
RightShoulderWeld.Part1 = RightShoulder.Part1
RightShoulderWeld.C0 = RightShoulder.C0
RightShoulderWeld.C1 = RightShoulder.C1
RightShoulderWeld.Parent = RightShoulder.Parent
RightShoulderWeld.Name = "RightShoulderWeld"
RightShoulder = RightShoulderWeld
local LeftShoulderWeld = Instance.new("Weld")
LeftShoulderWeld.Part0 = LeftShoulder.Part0
LeftShoulderWeld.Part1 = LeftShoulder.Part1
LeftShoulderWeld.C0 = LeftShoulder.C0
LeftShoulderWeld.C1 = LeftShoulder.C1
LeftShoulderWeld.Parent = LeftShoulder.Parent
LeftShoulderWeld.Name = "LeftShoulderWeld"
LeftShoulder = LeftShoulderWeld
--Elbow welds to keep the arms straight
RightElbow = Instance.new("Weld")
RightElbow.Part0 = RightShoulder.Part1
RightElbow.Part1 = UserBody.RightLowerArm
RightElbow.C0 = CFrame.new(0, -RightElbow.Part1.Size.Y/2, 0)
RightElbow.Name = "RightElbowWeld"
RightElbow.Parent = UserBody.RightLowerArm
LeftElbow = Instance.new("Weld")
LeftElbow.Part0 = LeftShoulder.Part1
LeftElbow.Part1 = UserBody.LeftLowerArm
LeftElbow.C0 = CFrame.new(0, -LeftElbow.Part1.Size.Y/2, 0)
LeftElbow.Name = "LeftElbowWeld"
LeftElbow.Parent = UserBody.LeftLowerArm
return RightShoulder, LeftShoulder
end
function RemoveJoints()
local WaistWeld = UserBody.UpperTorso:FindFirstChild("WaistWeld")
local NeckWeld = UserBody.Head:FindFirstChild("NeckWeld")
local RightUpperArm = UserBody.RightUpperArm:FindFirstChild("RightShoulderWeld")
local LeftUpperArm = UserBody.LeftUpperArm:FindFirstChild("LeftShoulderWeld")
local RightLowerArm = UserBody.RightLowerArm:FindFirstChild("RightElbowWeld")
local LeftLowerArm = UserBody.LeftLowerArm:FindFirstChild("LeftElbowWeld")
if WaistWeld then
WaistWeld:Destroy()
end
if NeckWeld then
NeckWeld:Destroy()
end
if RightUpperArm then
RightUpperArm:Destroy()
end
if LeftUpperArm then
LeftUpperArm:Destroy()
end
if RightLowerArm then
RightLowerArm:Destroy()
end
if LeftLowerArm then
LeftLowerArm:Destroy()
end
end
function HandsOnAttachments(RightShoulder, LeftShoulder)
--Find the positions on the wheel we want the hand to point to
local RightTargetPosition = CFrame.new(RightShoulder.Part0.CFrame:PointToObjectSpace(RightHand.WorldPosition)) *(RightShoulder.C0 - RightShoulder.C0.p)
local LeftTargetPosition = CFrame.new(LeftShoulder.Part0.CFrame:PointToObjectSpace(LeftHand.WorldPosition)) *(LeftShoulder.C0 - LeftShoulder.C0.p)
--Adjust target positions so that the center of the hand will point to target position, otherwise the top left part of the hand will point to target position
RightTargetPosition = RightTargetPosition *CFrame.new(-RightShoulder.Part1.Size.X/2, -RightShoulder.Part1.Size.Y/2, 0)
LeftTargetPosition = LeftTargetPosition *CFrame.new(LeftShoulder.Part1.Size.X/2, -LeftShoulder.Part1.Size.Y/2, 0)
--Rotate arms 90 degrees downward so that the end of the hand will point to target position
local RightC0 = CFrame.new(RightShoulder.C0.p, RightTargetPosition.p) *CFrame.Angles(math.rad(90), 0, 0)
local LeftC0 = CFrame.new(LeftShoulder.C0.p, LeftTargetPosition.p) *CFrame.Angles(math.rad(90), 0, 0)
RightShoulder.C0 = RightC0
LeftShoulder.C0 = LeftC0
end
--When someone sits in the vehicle seat
local RightShoulder, LeftShoulder = ConfigureJoints()
--Setup event that will move hands to the wheel
Stepped = game["Run Service"].RenderStepped:Connect(function()
for i, Part in pairs(UserBody:GetChildren()) do
if string.match(Part.Name, "Arm") or string.match(Part.Name, "Hand") then
Part.LocalTransparencyModifier = 0
end
end
HandsOnAttachments(RightShoulder, LeftShoulder)
end)
Model.Seat.ChildRemoved:connect(function(child)
if child.Name=="SeatWeld" then
RemoveJoints()
if Stepped then
Stepped:Disconnect()--Stop making the players hands stay on the wheel and stop memory leaks
end
script.Command:FireServer("Remove")
end
end)

Server Script

local On = true
local User = script.Parent.Parent
local UserBody = User.Character
local Model = script.Object.Value
local LeftHand = script.LeftHand.Value
local RightHand = script.RightHand.Value
local WaistAngle = math.rad(20) -- Back Forward Angle
local NeckAngle = math.rad(-15) -- Neck Forward Angle
---Create Welds identical to Motor6Ds to override animations
function ConfigureJoints()
local RightShoulder = UserBody:WaitForChild("RightUpperArm").RightShoulder
local LeftShoulder = UserBody:WaitForChild("LeftUpperArm").LeftShoulder
local RightElbow = UserBody.RightLowerArm.RightElbow
local LeftElbow = UserBody.LeftLowerArm.LeftElbow
--Torso Weld is to keep the player leaning forward so the arms reach the steering wheel
local TorsoWeld = Instance.new("Weld")
TorsoWeld.Part0 = UserBody.UpperTorso.Waist.Part0
TorsoWeld.Part1 = UserBody.UpperTorso.Waist.Part1
TorsoWeld.C0 = UserBody.UpperTorso.Waist.C0 *CFrame.Angles(-WaistAngle, 0, 0)
TorsoWeld.C1 = UserBody.UpperTorso.Waist.C1
TorsoWeld.Name = "WaistWeld"
TorsoWeld.Parent = UserBody.UpperTorso
--Neck weld is to make the player's head look up, since the UserBodyacter is leaning forward the head is naturally looking down, so we need to adjust
local NeckWeld = Instance.new("Weld")
NeckWeld.Part0 = UserBody.Head.Neck.Part0
NeckWeld.Part1 = UserBody.Head.Neck.Part1
NeckWeld.C0 = UserBody.Head.Neck.C0 *CFrame.Angles(-NeckAngle, 0, 0)
NeckWeld.C1 = UserBody.Head.Neck.C1
NeckWeld.Name = "NeckWeld"
NeckWeld.Parent = UserBody.Head
--Shoulder welds so we can make them move towards the steering wheel
local RightShoulderWeld = Instance.new("Weld")
RightShoulderWeld.Part0 = RightShoulder.Part0
RightShoulderWeld.Part1 = RightShoulder.Part1
RightShoulderWeld.C0 = RightShoulder.C0
RightShoulderWeld.C1 = RightShoulder.C1
RightShoulderWeld.Parent = RightShoulder.Parent
RightShoulderWeld.Name = "RightShoulderWeld"
RightShoulder = RightShoulderWeld
local LeftShoulderWeld = Instance.new("Weld")
LeftShoulderWeld.Part0 = LeftShoulder.Part0
LeftShoulderWeld.Part1 = LeftShoulder.Part1
LeftShoulderWeld.C0 = LeftShoulder.C0
LeftShoulderWeld.C1 = LeftShoulder.C1
LeftShoulderWeld.Parent = LeftShoulder.Parent
LeftShoulderWeld.Name = "LeftShoulderWeld"
LeftShoulder = LeftShoulderWeld
--Elbow welds to keep the arms straight
RightElbow = Instance.new("Weld")
RightElbow.Part0 = RightShoulder.Part1
RightElbow.Part1 = UserBody.RightLowerArm
RightElbow.C0 = CFrame.new(0, -RightElbow.Part1.Size.Y/2, 0)
RightElbow.Name = "RightElbowWeld"
RightElbow.Parent = UserBody.RightLowerArm
LeftElbow = Instance.new("Weld")
LeftElbow.Part0 = LeftShoulder.Part1
LeftElbow.Part1 = UserBody.LeftLowerArm
LeftElbow.C0 = CFrame.new(0, -LeftElbow.Part1.Size.Y/2, 0)
LeftElbow.Name = "LeftElbowWeld"
LeftElbow.Parent = UserBody.LeftLowerArm
return RightShoulder, LeftShoulder
end
function RemoveJoints()
local WaistWeld = UserBody.UpperTorso:FindFirstChild("WaistWeld")
local NeckWeld = UserBody.Head:FindFirstChild("NeckWeld")
local RightUpperArm = UserBody.RightUpperArm:FindFirstChild("RightShoulderWeld")
local LeftUpperArm = UserBody.LeftUpperArm:FindFirstChild("LeftShoulderWeld")
local RightLowerArm = UserBody.RightLowerArm:FindFirstChild("RightElbowWeld")
local LeftLowerArm = UserBody.LeftLowerArm:FindFirstChild("LeftElbowWeld")
if WaistWeld then
WaistWeld:Destroy()
end
if NeckWeld then
NeckWeld:Destroy()
end
if RightUpperArm then
RightUpperArm:Destroy()
end
if LeftUpperArm then
LeftUpperArm:Destroy()
end
if RightLowerArm then
RightLowerArm:Destroy()
end
if LeftLowerArm then
LeftLowerArm:Destroy()
end
end
Model.Seat.ChildRemoved:connect(function(child)
if child.Name=="SeatWeld" then
On = false
RemoveJoints()
script:Remove()
end
end)
function HandsOnAttachments(RightShoulder, LeftShoulder)
--Find the positions on the wheel we want the hand to point to
local RightTargetPosition = CFrame.new(RightShoulder.Part0.CFrame:PointToObjectSpace(RightHand.WorldPosition)) *(RightShoulder.C0 - RightShoulder.C0.p)
local LeftTargetPosition = CFrame.new(LeftShoulder.Part0.CFrame:PointToObjectSpace(LeftHand.WorldPosition)) *(LeftShoulder.C0 - LeftShoulder.C0.p)
--Adjust target positions so that the center of the hand will point to target position, otherwise the top left part of the hand will point to target position
RightTargetPosition = RightTargetPosition *CFrame.new(-RightShoulder.Part1.Size.X/2, -RightShoulder.Part1.Size.Y/2, 0)
LeftTargetPosition = LeftTargetPosition *CFrame.new(LeftShoulder.Part1.Size.X/2, -LeftShoulder.Part1.Size.Y/2, 0)
--Rotate arms 90 degrees downward so that the end of the hand will point to target position
local RightC0 = CFrame.new(RightShoulder.C0.p, RightTargetPosition.p) *CFrame.Angles(math.rad(90), 0, 0)
local LeftC0 = CFrame.new(LeftShoulder.C0.p, LeftTargetPosition.p) *CFrame.Angles(math.rad(90), 0, 0)
RightShoulder.C0 = RightC0
LeftShoulder.C0 = LeftC0
end
--When someone sits in the vehicle seat
local RightShoulder, LeftShoulder = ConfigureJoints()
--Setup event that will move hands to the wheel
while On == true do
wait()
for i, Part in pairs(UserBody:GetChildren()) do
if string.match(Part.Name, "Arm") or string.match(Part.Name, "Hand") then
Part.LocalTransparencyModifier = 0
end
end
HandsOnAttachments(RightShoulder, LeftShoulder)
end