I want to make a game that has a lot of tweening, especially on parts. Apparently tweening on the server gets really laggy and can make tweens look choppy, so how would I go about doing it on the client? Do I create the tween on the server and send it to the client? And why does such thing happen?
What you should do to optimize the tweening is to use RemoteEvent:FireAllClients().
Then, the change will be replicated to every client.
The reason why the server shouldn’t handle tweening is because it has a lot of other tasks, you might notice the server skips a few “steps” when doing so on the server-side.
I don’t know why it happens but it does
Don’t send the tween or anything from the server though. When you want to tween something just send a message to the client to tween this part and if you want you can send over the TweenInfo and the property table
Ex
-- Client accepting the tween request
local tweenservice = game:GetService("TweenService")
event.OnClientEvent:Connect(function(properties, tweeninfo, object)
local tween = tweenservice:Create(object, tweeninfo, properties)
tween:Play()
end)
This is just a example
As for why it happens, its because when you tween on the server the tween has to tell every single client EVERY SINGLE TIME it moves even just a little bit, as opposed to telling the client to just deal with it a single time
Server sided tween:
Player1, move part1 to 0.51252951,0,0
Player2, move part1 to 0.51252951,0,0
Player3, move part1 to 0.51252951,0,0
Player4, move part1 to 0.51252951,0,0
Player5, move part1 to 0.51252951,0,0
Player1, move part1 to 0.52252951,0,0
Player2, move part1 to 0.52252951,0,0
Player3, move part1 to 0.52252951,0,0
Player4, move part1 to 0.52252951,0,0
Player5, move part1 to 0.52252951,0,0
Player1, move part1 to 0.53252951,0,0
Player2, move part1 to 0.53252951,0,0
Player3, move part1 to 0.53252951,0,0
Player4, move part1 to 0.53252951,0,0
Player5, move part1 to 0.53252951,0,0
continues on for 20 more times…
You can see how this is a problem
As opposed to
Client sided tween:
Player1, tween part1 from 0.5 to 1
Player2, tween part1 from 0.5 to 1
Player3, tween part1 from 0.5 to 1
Player4, tween part1 from 0.5 to 1
Player5, tween part1 from 0.5 to 1
Not to mention latency issues, if someone has a ping spike in the middle of the server sending tween data, it would be extremely choppy because theres a delay in the constant stream of data given to the client
This worked perfectly and everything was smooth, but I noticed there was a slight delay between me, say, interacting with a button and the tween playing. How do I fix that?
Most likely just your latency(ping)
To my knowledge there isn’t a way to fix this one without doing everything on the client
If the part has to be seen tweening by all other players then you want the server to tell them to tween
If it only has to be seen by you then you can do the click detection and tweening on the client
Well I was planning on having my game just be singleplayer so would the second option be good?
Well then yes it would be fine to do more on the client if its singleplayer
Thanks for the explanation! [30]
Are you sure about that? Tweening on the server might already be replicating the tweens to all clients
Yeah Im pretty sure
If you do a test where you unplug your internet in the middle of a tween it stops immediately, it doesnt follow through with the tween until its finished