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!
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)
Would firing that many remote events cause lag?
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.
What do you mean tween operations into multiple arrays?
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.
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)
Thank you for the advice I will try it tomorrow! I will let you know if it works.
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:
I got it to work. Thank you to all of your ideas!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.