Hello, I have tried to make a server-client ball system to combat delay. However, the lag is still visible on the client due to network ownership switching. I have tried updating the client ball’s position to the server ball in a runservice loop along with pausing the loop for a split second when the ball gets hit. The server ball’s network ownership is set to nil in a while loop, but the client ball isn’t so it automatically switches network ownership to the nearest player. This makes it look choppy on the client, but I do not know how to combat this because if I set the client ball’s network ownership to nil, it can not be tweaked on the client.
I forgot to mention that this is for a volleyball system, here is the loop being used
local con
con = game:GetService("RunService").RenderStepped:Connect(function()
for i,v in pairs(workspace:GetChildren()) do
if v.Name == "ServerBall" then
if (v.GameBall and v:WaitForChild("GameBall"):GetAttribute("Upddate") == true ) or (v.GameBall and v:WaitForChild("GameBall"):GetAttribute("Update") == nil ) then
v.GameBall.Position = v.Position
end
end
end
end)
You can create ball on every client and have one main ball on the server, this way everyone can have smooth experience without network ownership, this is possible solution
The client ball is already being replicated on every client (the loop is in a local script)
Bump also i made it a bit better by changing around some waits but the jolt is still pretty visible
why do you need to tweak it on the client and could you send a video of the ball
I started trying to use tweenservice but here’s a video(right now its affecting spiking a lot):
robloxapp-20241128-1620046.wmv (1.1 MB)
here’s the updated loop:
local con
con = game:GetService("RunService").RenderStepped:Connect(function()
for i,v in pairs(workspace:GetChildren()) do
if v.Name == "ServerBall" then
if v.GameBall then
v.GameBall:SetAttribute("Active", v:GetAttribute("Active"))
end
if (v.GameBall and v:WaitForChild("GameBall"):GetAttribute("Update") == true ) or (v.GameBall and v:WaitForChild("GameBall"):GetAttribute("Update") == nil ) then
if (v.GameBall.Position - v.Position).Magnitude > 0.5 then
local tweeni = TweenInfo.new(0.1, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false)
local goal = {Position = v.Position}
local tween = ts:Create(v.GameBall, tweeni, goal)
tween:Play()
else
v.GameBall.Position = v.Position
end
end
end
end
end)
Renderstepped actually can cause a decent amount of lag. The documentation for renderstepped states that you should use it sparingly.
You could try using a different runservice event instead possibly. That might reduce the lag.
Is while loops worse? I’m not sure about this
Edit: from my little research run service uses FPS so probably not suitable try while loops and see what happens
alright i will try it
charlimitcharlimitcharlimit
Its not really any better with a while loop
I think while loops run faster so it might be worse.
have you tried a different runservice event like heartbeat or stepped it might cause less lag
Ok so i used heartbeat and it’s better but there is still some jitter and it is significantly desynced
here’s a video:
robloxapp-20241128-1723121.wmv (489.4 KB)
That’s simply how :SetNetworkOwner()
works! I think some people have mentioned this, but you could have a ball on the clientside and have that one try and replicate the movement of the server ball.
You could set the linearvelocities and angularvelocities to the same as the serverball, and teleporting it if the desync is too high.
That said, iirc most volleyball games use tweening instead of actual physics. Maybe look into that.
Without any testing or benchmarking of the code it is plainly obvious why this is lagging. You are iterating every single child of the workspace every step, i.e. every 4ms, which equates to 250 times a second! And regardless of the time it takes to complete an iteration you continually start another iteration, and maybe even create and play a tween too. All in parallel!!
That’s already what I’ve been trying to do but it still jitters a bit, not as much as if I didn’t use a server ball though
I think a way to stop this is by not using a loop at all with tweens, instead just use velocity or something. Where it’s a simple event.
You could try lerping possibly. Or make sure the ball is anchored and you know turn off physicalproperties and whatever
If I don’t loop, it will be de synced on other clients