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 vehicle.
What is the issue? Include screenshots / videos if possible!
I have a vehicle that moves by tweening to the move direction(It’s flying vehicle). When a one player drives this vehicle, for others this vehicle moves as if teleporting.
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.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
OnMoveDirectionChanged = hum:GetPropertyChangedSignal("MoveDirection"):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)
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
Seems like you’re tweening the vehicle inside a local script which replicates to the local player only, in this case the driver. Obviously you cant move this script to a serverScript cause it would be laggy, what you can do is make a script in ServerScriptService which would replicate the tween to all other clients (so the driver would tween in real time while the rest of the server would see the tween via their own local scripts). You can put a remote event right before the end of your OnMoveDirectionChanged function just after the tween function. That remote event would alert the server. In the server you would put a script which would fire a remote event back to the rest of the clients:
OnMoveDirectionChanged = hum:GetPropertyChangedSignal("MoveDirection"):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})
for _,v in pairs(game.Players:GetPlayers()) do
if v ~= player then -- so that the remote wont be fired on the local player and tween twice
game.ReplicatedStorage.TweenTheDriverToOtherClients:FireClient(v, player) -- change the remote event to whatever name you like, we send the driver as an arguement so that other clients know which character to tween in their screens
end
end
end)
Then on every client you should put a script like:
Note: I’m assuming script.Parent.Parent is a HumanoidRootPart where the bodyVelocity is applied, if not then change the driverPlayer.Character.HumanoidRootPart.BodyVelocity part of the last serverScript to wherever bodyVelocity is
I am very grateful for the help. I’m sure your method would definitely work, but my only concern is that if the MoveDirection changes too often and fires RemoteEvent too many times, then the RemoteEvent that passes information to other clients will break down due to the fact that there is a limit on the use of RemoteEvents.
I also forgot to note what script.Parent.Parent is. In fact, this is the transport itself, and not the HumanoidRootPart of the character.
I mean yeah you don’t want to send many remote events in a short period of time thats true. I suggest you try this method out and try to change the move direction as many times as you can in short period of time to test its limits. If remote events break down tell me and I’ll try to figure smth out. I know that remote events cap at 20 events per second but reaching that limit will lag your game significantly. In the mean time you could also try searching on youtube ways to make a flying vehicle (There was a gear on roblox back in 2015-2018 called I think rainbow carpet or something which, in games, would fly around very similarily to your cloud. The gear still exists but you cant use it pretty much anywhere anymore. You can check out how that works and see what you can do to make it similar)
If remote events are completely out of the option, I can think of another option. You can set the network ownership of the vehicle to the player, and the tween should be replicated to the server. However, this solution presents a risk to security, as the server is unable to validate the physics. Read this excerpt from the wiki.
Roblox cannot verify physics calculations when a client has ownership over a BasePart. Clients can exploit this and send bad data to the server, such as teleporting the BasePart, making it go through walls or fly around.
Additionally, BasePart.Touched events are tied to network ownership, meaning that a client can fire Touched events on a BasePart it owns and send it to the server, even if the server doesn’t see it touch anything. For example, a client can make a sword deal damage to another player across the map by firing the event through script injections, so it’s important to check the validity of such events fired by clients.
What I may suggest is creating some sort of system, both on the client and server, that prevents sending/accepting events if a bunch of requests have been made in a short period of time.