You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I want to achieve a smooth ride on my flying vehicle. -
What is the issue? Include screenshots / videos if possible!
I have a vehicle that moves in air by tweening. When a one player drives this vehicle, for others this vehicle moves really laggy.
When the player just got into the vehicle, he drives normally for 1-2 seconds, and then the vehicle starts to extreme lagging for others.
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I looked through a bunch of topics, but I don’t think I found my case.
local movement = {forward = 0, backward = 0, right = 0, left = 0}
local function movementBind(actionName, inputState, inputObject)
if inputState == Enum.UserInputState.Begin then
movement[actionName] = 1
elseif inputState == Enum.UserInputState.End then
movement[actionName] = 0
end
return Enum.ContextActionResult.Pass
end
game:GetService("ContextActionService"):BindAction("forward", movementBind, false, Enum.PlayerActions.CharacterForward)
game:GetService("ContextActionService"):BindAction("backward", movementBind, false, Enum.PlayerActions.CharacterBackward)
game:GetService("ContextActionService"):BindAction("left", movementBind, false, Enum.PlayerActions.CharacterLeft)
game:GetService("ContextActionService"):BindAction("right", movementBind, false, Enum.PlayerActions.CharacterRight)
OnMoveDirectionChanged = game:GetService("RunService").RenderStepped:Connect(function()
local CameraCFrame = workspace.CurrentCamera.CFrame
local direction = CameraCFrame.RightVector*(movement.right-movement.left)+CameraCFrame.LookVector*(movement.forward-movement.backward);
if (direction:Dot(direction)>0) then
direction = direction.unit;
end
Tween(script.Parent.Parent.BodyVelocity,1.5,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,{Velocity = direction*50})
end)
.
The script above is LocalScript and is located inside the vehicle’s part, which is affected by BodyVelocity.
The LocalScript itself is executed using the server script ( which is located inside VehicleSeat ) by using InvokeClient on RemoteFunction:
-- server script
script.Parent:GetPropertyChangedSignal("Occupant"):Connect(function()
if script.Parent.Occupant and script.Parent.Occupant.Parent then
local plr = game:GetService("Players"):GetPlayerFromCharacter(script.Parent.Occupant.Parent)
if plr then
script.Parent.RemoteFunction:InvokeClient(plr)
-- LocalScript which tweens vehicle starts working
end
end
end)
.
This is my second post about the same problem because I didn’t get an answer on my first post.