Smoothing Tween

Hello,
I have been messing around with a tower defense game and I wanted to tween the enemies. The only issue with this is that the tween looks great on the server but on the client, it is choppy due to client replication lag. Does anyone have suggestions to make the client side less choppy?
Thank you, for reading!

1 Like

You could use a RemoteEvent which fires the client telling it what to tween with parameters.

Client:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local remote = ReplicatedStorage.SmoothTween

remote.OnClientEvent:Connect(function(part, info, properties)
  local tween = TweenService:Create(part, info, properties)
  tween:Play()
  -- optional: tell server we finished
  tween.Completed:Connect(function()
    remote:FireServer("tween_finished", part)
  end)
end)

Server:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remote = ReplicatedStorage:WaitForChild("SmoothTween")

remote:FireAllClients(part, TweenInfo.new(1), {
  Size = Vector3.new(0, 1, 2)
})

Also, if you need to keep using tweens in your tower defense game, please consider writing an animation system (where its replicated from server to client, or fully handled on client)

1 Like

Would firing that many remote events cause lag?

1 Like

Maybe? If so, you can consider rewriting this example in BridgeNet2 or something which compresses calls. You can also group up tween operations into multiple arrays.

1 Like

What do you mean tween operations into multiple arrays?

1 Like

Basically, you need to manage tweens on the client. As long as if the server can in some way inform the client of how to tween it you should be good. Note that when you tween on the server, the server is sending constant updates about the position of the tweened object. Meaning you’re likely saving network usage on sending tween information with nearly any given implementation.

2 Likes

Something like this:

local operations = {}
local remote = <path_to_remote>
table.insert(operations, {
  instance = instance,
  tweenInfo = TweenInfo.new(1),
  properties = { Size = Vector3.zero }
})

table.insert(operations, {
  instance = instance2,
  tweenInfo = TweenInfo.new(1),
  properties = { Size = Vector3.one }
})

remote:FireAllClients(operations)

--> into client code
remote.OnClientEvent:Connect(function(operations)
  for _, operation in operations do
    local tween = TweenService:Create(operation.instance, operation.tweenInfo, operation.properties)
    tween:Play()
    -- if you want you can add completed handler
  end
end)
1 Like

Thank you for the advice I will try it tomorrow! I will let you know if it works.

2 Likes

Any server-owned physics interactions performed on the Server will look choppy to Clients.
The physics needs replication to the Client, or you can use Network Ownership on the Server to smooth the physics for a particular Client:

For the approach involving replication, this has been solved.
Please see:

1 Like

I got it to work. Thank you to all of your ideas!

1 Like

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