Should I handle Tweens on the client?

So my game has a lot of Tweening objects like doors, curtains, levers, etc.
I handle the Tweens on the server, and Im surprised how laggy the Tweens are when handled on the server.

Should I make the Tweens on the client instead?

So for instance:
ServerScript in door model:

local object = workspace.Door.PrimaryPart
    local info = {
    5,
    Enum.EasingStyle.Quad,
    Enum.EasingDirection.InOut
    }

local goals = {
CFrame = object.CFrame * CFrame.Angles(0,math.rad(80),0)
}

local remote = game.ReplicatedStorage.Events.TweenRemote:FireAllClients(info, goals, object)
wait(info[1])
object.CFrame = goals["CFrame"]

LocalScript:

game.ReplicatedStorage.TweenRemote.OnClientEvent:Connect(function(info, goals, obj)
    local newInfo = TweenInfo.new(info[1], info[2], info[3])
    local tween = TweenService:Create(obj, newInfo, goals)
    tween:Play()
end)

Would this be good to do?
Is there any changes I should make?
Will all clients have synced up Tweens (with low fps or high ping)?

Thanks in advance!

3 Likes

You should handle tweens client side. The lag can be insane when tweens are many serverside tweens.

5 Likes

Should I use the script I provided in the post to do that?
Or do I need to change something

1 Like

i don’t know. I’m a bit tired right now.

1 Like

The script you provided would work fine on a local script. Like @ImTheBuildGuy said, Server Tweens can look laggy because of replication delay

2 Likes

I tested it out and it seems good even with low fps, unsure about high ping though.
Would ping affect the replication across clients?

Also the only problem I noticed is that if you put a part in the way of the door, it wont get pushed since on the server the door snaps into position, but there isnt any physics based stuff in my game so I should be fine.

also wow its actually the real sub, hi there

2 Likes

I suggest running everything client-sided if you’re making an obby; like ToH (Tower of Hell) they run everything client-sided, meaning not sending messages to the server as the next thing could happen:
You send a message to every client (1 of the clients has 5 seconds delay)
then you send another message to the client (now with 2 seconds delay), now the tween will take place while for the client tween1 hasn’t finished yet.
Edit: So nothing server-sided (no events etc)

But then the other players wouldnt see if the door is open or not

I suggest using hinges, forces or anything else for the doors not tweening.
As that runs smooth on client when you change it on the server.

Hinges and forces are a lot more prone to glitching out, I dont think thats a good idea

Ping/Latency is the time it takes for a client to receive data from the server - when you Tween on the server, the client is being sent the physical position data, which means ping definitely would make a difference as far as I know

Also hi o/

If other players need to see the door, you can update the door on the server and animate the Tween on the client?

Not true, I use hinges myself for my doors and I lock them in place when they’re not moving so they won’t glitch out.
I made a closet door with this (so 2 doors 1 stuck to the other and they rotate oposite directions)
I couldn’t make this with tweening/cframes or anything else; I could show you how I made it work if you wish.

Note, I use a HingeConstraint not HingeSurface

How would you control the door through Hinges?

Simple, you’d first place 2 attachments on 2 parts, 1. the anchored part (anchored = true), 2. The door (anchored = false), then you’d make the ActuatorType of the HingeConstraint Servo,
Then make the ServoMaxTorque a high number so you can’t push it around (such as 10000000000)
then you set the AngularSpeed, which determines how you want to rotate it and you put in a TargetAngle in degrees how much you want to rotate it.
image
Then what you should play with is changing the TargetAngle or the AngularSpeed
Note, you can tween the speed out so the Speed will slow/get quicker when you open/close

Note, both attachments would need to have the same
WorldPosition and WorldOrientation else the attachments will teleport to each other;
Attachment0:
image
Attachment1:
image

I actually just tried to DDOS myself and peaked at around 3k ping (wow im good at this lmao)

The only difference was that the door was opening and closing waaay after you clicked it, which is same as if you were to do it on the server I suppose
The door also teleported around sometimes, but then again I dont expect any player to have 3000 ping.

200 ping is still fine.

Either way, I suggest using HingeConstraints as this will only have a delay with like clicking on it, tho what you could do is make it client-sided and send messages to other clients so it’d be smooth for a laggy client instead of the client having to wait.

Tweens are usually made client side, but if you would like to, you can make them server sided. Note: Client sided tweens will not appear for any other players other than the local player.