Soccer ball system has a short delay before applying velocity on other client's screen

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to achieve smooth, lagless, and responsive ball velocity on all clients.

  2. What is the issue? Include screenshots / videos if possible!
    When applying velocity, Client A sees no delay (Client A has networkownership). However, On client B there is a small delay before the ball starts moving.

https://gyazo.com/6d6938d19b6d3fadb0e4a2d8925d21bc

Important code:

Client (This is a remote event):

ApplyImpulse:Connect(function(data)
	local Velocity = data.vel
	local Position = data.pos
	local Timestamp = data.t
	local Kicker = game:GetService("Players"):FindFirstChild(data.p)
	local Character = Kicker.Character
	local HRP = Character:WaitForChild("Ball")
	local Connection = HRP:FindFirstChild("Ball")
	if Connection and Connection:IsA("Motor6D") then
		Connection:Destroy()
	end
	Ball:ApplyImpulse(Vector3.new(Velocity[1],Velocity[2],Velocity[3]))
end)

Server (On Ball kick):

ShootEvent:Connect(function(Player : Player,Power : number,Velocity : Vector3)
	print(Player, Ball.Owner)
	if Player == Ball.Owner then
		local Model = Ball.Model
		local Position = Model.Position
		Velocity *= Power
		print(Power)
		Model:FindFirstChild("Trail").Enabled = true
		Ball:UnAttach(Player)
		Ball:SetOwner(nil, false, false)
		dataToSend = {
			pos = {Position.X,Position.Y,Position.Z},
			vel = {Velocity.X,Velocity.Y,Velocity.Z},
			--t = compressTimestamp(Timestamp)
			p = Player.Name
		}
		repeat task.wait() until not Ball:IsAttached(Player)
		ApplyImpulse:Fires(false,dataToSend)
		CanPickup = false
		task.delay(.2, function()
			CanPickup = true
		end)
		VFX:Fires(false,"StraightShot",Player.Character,Model,Power)
		return true
	else
		return false
	end
end)

Note: Im using Warp for the remote events. :Fires is the equivalent for :FireAllClients.

5 Likes

bump bc this is kinda important

2 Likes

Update: After debugging for a while I found out that, even though I am manually assigning Network ownership when the player picks up the ball, After unattaching the ball from the player the network ownership goes back to nil. For that reason, I have to call:

Ball.Model:SetNetworkOwner(Player)

Right after unattaching the ball, which is probably resulting in that delay.
Any ideas how to fix this?

1 Like

Why would you want the network ownership when its not in anyone’s possession? , it could easily be tampered with hence the player has more server to client control of it.

1 Like

When shooting i need to give the client network ownership to applyimpulse on the client. applying velocity on the server is simply too laggy for my needs.

i don’t really unedrstand what you mean by this–can you elaborate?

I’d recommend just replicating this on the server only, there’s only one ball instance. Futhermore, once the player gains possession, you set the ball PrimaryPart/Root which connects to all its descendants network owner to the player, make sure you build these welds – I’m assuming your welding the ball – and then when kicking/releasing, It would be best to connect it to some remote function to release the ball so the holder would know when its successfully been released or not without firing a remote event back; and the server would obviously remove the network ownership.

1 Like

Could you clarify what you mean by “replicating this”? Should I keep the ball’s network ownership to the server only? And also, I’m not welding the ball. I’m using motor6Ds so I can animate it while I have possession of it.

Client → picks up ball, sends remote to validate hitbox
Server → Validates and sets network ownership of the ball to the player.

client → shoots ball, sends remote to server
Server → Validates and fires remote to all clients to apply impulse on their screen with given direction

Same thing..


You cant call the function on client side – I dont understand this question…


And from what I’ve seen your doubling the result but the client already has access to it, Do you not know how SetNetworkOwnership works?

Once you set the ownership, everything the client does to it is automatically replicated to the server without any interference to other clients as they’re seeing this on the SERVER.

you probably shouldnt be setting network ownership to the client as that can be very bad for hackers.

Server/Client validation comes in to play, buy you worry about things like this later on.

By welds I thought you were referring to WeldConstraints or Welds.

The reason I’m using fireallclients is if for example
the player that is shooting the ball has high latency
/ ping making their changes to the ball not replicate quickly, the other clients can apply the impulse on their screen so the ball doesn’t just stay in place

I’m using server/ client validation

So let me get this straight? you want to replicate a ball that hasn’t been sent to any of the clients yet and then shoot? like prediction, if so your talking to the wrong person.

I’ve answered before and I’d like you to refer back to those responses, I will be leaving his topic at hand to someone else.

Yes, I am talking about prediction. However this post isn’t about prediction. It is about Network ownership.

try check latency between server and client through that remote

Its in studio so the latency is like nothing.. the problem is the network ownership switching and it causes that delay.. if I don’t find a solution I’ll probably write custom physics and whatnot.

I think you should just do it on the server. if you’re worried about the client delay, youo can prob just do smth visual for them or sumn

bump because I got the same delay issue when i tried ApplyImpulse for combat knockback