Linear velocity doesn't replicate ball's position on client

Please read this post to the end before posting.

I am sure that there are no any errors in my script.

I am using linear velocity to move the ball.

What’s the issue?
The issue is that on server side ball’s position is ok but it’s position on client side it is not where it should be.

The script is solely on server side.
There is nothing that changes ball’s position on client side.
I tried setting network owner to nil but it didn’t really help.
Also I tried setting ball’s position manually (Ball.Position = Ball.Position) but that didn’t really help lol

How should it work?
It should create ball
It should make the ball to move along waypoints
I made it to stop after reaching each one of the waypoints
You may notice that ball is moving a little bit further than waypoint on server side but that is not crucial.

Footage:

The code:

task.wait(7) -- Waiting so that I can have some time before the thing happens
local Ball = Instance.new("Part")
Ball.Shape = Enum.PartType.Ball.Name
Ball.Name = "Ball"
Ball.Parent = workspace
Ball:SetNetworkOwner(nil)
Ball.CanCollide = false
Ball.Anchored = false
Ball.Size = Vector3.new(2,2,2)
Ball.Material = Enum.Material.Neon

local Speed = 100 -- Ball's speed

local atch = Instance.new("Attachment")
atch.Parent = Ball

local LV = Instance.new("LinearVelocity")
LV.Enabled = false
LV.Parent = Ball

LV.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
LV.Attachment0 = atch
LV.MaxForce = math.huge

local wps = workspace.WPS:GetChildren()

for i = 1, 5 do 
	local WayPointPosition = wps[i].Position
	local distance = (WayPointPosition - Ball.Position).Magnitude -- calculating distance between waypoint and ball position

	local Vel = (WayPointPosition - Ball.Position).Unit * Speed -- it calculates velocity so the ball is moving to the next waypoint.
	LV.VectorVelocity = Vel
	Ball.Anchored = false
	LV.Enabled = true

	local Time = distance/Speed -- calculating time based on distance and speed

	task.wait(Time) -- waiting

	print("Distance:",(WayPointPosition - Ball.Position).Magnitude)

	game:GetService("RunService").Heartbeat:Wait() -- making sure physics are done (I hope so)
	task.wait() -- just to be sure enough
	
	LV.Enabled = false
	Ball.AssemblyLinearVelocity = Vector3.zero
	Ball.Anchored = true
	task.wait(2) -- just making ball to stop here to check how it works
end

LV.Enabled = false
Ball.AssemblyLinearVelocity = Vector3.zero
Ball.Anchored = true

I am bumping the thead cuz no one is responding…
Should I just make bug report topic?

Maybe try using .Stepped instead of .HeartBeat

That didn’t help, but thanks for trying tho

This is an already known physics bug, LinearVelocity doesn’t properly replicate to Client, it works fine on Client tho. The only issue is just when it’s from Server → Client

1 Like

That occured not only with LinerVelocity but also with BodyVelocity
It turns out that replication was delayed after anchoring the ball. But it was resumed as soon as I unanchored the ball.
Also if I do this:

Ball.Anchored = true
Ball.Position = Ball.Position + Vector3.new(0,0,0.001)

Then Ball will just teleport to it’s true position as if it noticed that it was doing wrong.

Even making my own linear velocity (sort of) didn’t help because position was still delayed:

local wps = workspace.WPS:GetChildren()

for i = 1, 5 do 
	local WayPointPosition = wps[i].Position
	local distance = (WayPointPosition - Ball.Position).Magnitude -- calculating distance between waypoint and ball position

	local Vel = (WayPointPosition - Ball.Position).Unit * Speed -- it calculates velocity so the ball is moving to the next waypoint.

	local Time = distance/Speed -- calculating time based on distance and speed
	local Connection = nil
	
	Connection = RunService.Stepped:Connect(function()
		Ball.AssemblyLinearVelocity = Vel
	end)
	
	task.wait(Time) -- waiting
	Connection:Disconnect()
	print("Distance:",(WayPointPosition - Ball.Position).Magnitude)
end
Ball.Anchored = true
Ball.Position = Ball.Position + Vector3.new(0.001,0.001,0.001)

That’s why I decided to update not only ball’s Linear velocity but also ball’s position and it really turned out to be the solution (even tho ball’s position was a bit laggy)!

local RunService = game:GetService("RunService")

task.wait(7) -- Waiting so that I can have some time before the thing happens
local Ball = Instance.new("Part")
Ball.Shape = Enum.PartType.Ball.Name
Ball.Name = "Ball"
Ball.Parent = workspace
Ball:SetNetworkOwner(nil)
Ball.CanCollide = false
Ball.Anchored = false
Ball.Size = Vector3.new(2,2,2)
Ball.Material = Enum.Material.Neon

local Speed = 100 -- Ball's speed

local wps = workspace.WPS:GetChildren()

local Updated = false

for i = 1, 5 do 
	local WayPointPosition = wps[i].Position
	local distance = (WayPointPosition - Ball.Position).Magnitude -- calculating distance between waypoint and ball position

	local Vel = (WayPointPosition - Ball.Position).Unit * Speed -- it calculates velocity so the ball is moving to the next waypoint.
	--LV.Velocity = Vel

	local Time = distance/Speed -- calculating time based on distance and speed
	local Connection = nil
	
	Connection = RunService.Stepped:Connect(function()
		Ball.AssemblyLinearVelocity = Vel
		if Updated then
			Ball.Position += Vector3.new(0,0,0.001)
		else
			Ball.Position -= Vector3.new(0,0,0.001)
		end
		Updated = not Updated
	end)
	
	task.wait(Time) -- waiting
	Connection:Disconnect()
	print("Distance:",(WayPointPosition - Ball.Position).Magnitude)
end
Ball.Anchored = true
Ball.Position = Ball.Position + Vector3.new(0.001,0.001,0.001)

Result:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.