I have a train game. But the trains are slowing down due to server-lag, as was told by me by another user . They said I should instead, run the self-driving trains on the client instead of the server. I do have several questions however.
-If the trains are run on the client, will they all be on sync?
-If a player seats on the train, will it appear to other players
-If a players train, as an example, derails and gets fixed (Teleports it back to the start of the tunnel), does it mean that the train for that player will no longer be in sync with the rest of the server. (If that was to happen)
If you guys do have any idea on how to reduce server lag, please respond to this post: Trains lagging {URGENT}
It would be a bad idea to switch the train to clint script.
Answers For Your Questions
=> Nope, they won’t be on sync.
=> If the player sits on the train, for other players, only the player appears moving and nothing else. It would be like the player just flying around for other players.
=>Yep, if that happens, only that player would have the train at start and rest all wouldn’t have it from start. It wouldn’t sync.
I would suggest you to try to reduce server lags instead of switching it to clint script
that would do but will also give hackers the entire access to that game. That’s not the best idea.
you can use remote events for each and everything but that would increase the memory usage and the ping very badly. That’s not a good idea either…
create a CFrame value inside of the train
then use TweenSerivce to tween the Value
something like this should work
local TrainModel = game.Workspace.Train
local TweenValue = Instance.new("CFrameValue")
TweenValue.Name = "Tween"
TweenValue.Parent = TrainModel
TweenValue.Value = TrainModel:GetPivot()
local connection
local function moveTrain()
TrainModel:PivotTo(TweenValue.Value)
end
connection = TweenValue.Changed:connect(moveTrain)
local TweenService = game:GetService("TweenService")
local ENDPOSITION = game.Workspace:WaitForChild("End"):GetPivot()
TweenService:Create(TweenValue,TweenInfo.new(0.2,Enum.EasingStyle.Linear,Enum.EasingDirection.In),{Value = ENDPOSITION}):Play()
OR you can just use normal bodymovers such as LinearVelocity or something similar,
BUT if you use these you MUST set the network owner of the PrimaryPart to nil
To do this you use this RootPart:SetNetworkOwner(nil)
this lets the server know that the movement of the train is controlled by the server
TweenService doesn’t allow you to tween a whole model (unless you tween the PrimaryPart of the Model). However this script gets around that by tweening the Value of a CFrameValue instance. And when the Value is changed, the script then Pivots the Model (via PivotTo() ) to the new Value