Best way to animate sliding doors for all players on the client side with StreamingEnabled

Hey!

Depending on what the answer is to question 1, I may need to rewrite my code on how the doors open.

Question 1:
What would be more optimized? When a player a pushes a button a door will slide open/close, would it be better to make it so once the button is pushed it uses FireServer() to open/close the door or would it be better to make it so once the button is pressed, it uses FireServer() to fire an event that will FireAllClients() to open/close the door for all clients? By far from I’ve read it is better to go for option 2 which is the FireAllClients method, but I’m seeing what people will comment here.

Currently, I am using method 1 which is the FireServer method but, if I am correct that using method 2 is more optimized then I plan to rewrite my code so it uses method 2. If this is a case then please go on and read question 2!

Question 2: How could I rewrite my code to use method 2? It needs to be compatible with streaming enabled. My thoughts are, once the doors is finished playing the lerping animation that opens/closes the doors, that the CFrame of the door will set the CFrame of the end CFrame on the server to ensure the door is opened/closed, just incase the door gets streamed in to any clients after the animation was played before the door was streamed in. One problem I’ve got about this is, if the door gets streamed in while the door is lerping, I don’t want the door to instantly go to the finished CFrame at the end of lerping animation and I don’t want the door to be 20% opened for the player that just had the door streamed in and the door to be 60% opened for the player that had the door streamed in since the animation started.

An attritional question to this, what would my options be if the door streamed out while the animation is playing?

Question 3: Would it be worth to just change the Doors ModelStreamingMode to Persistent? That way the doors will animate no matter how close or far the player is from the door (Question: Does setting a Models ModelStreamingMode to Persistent mean that the model load in straight away and never stream out and act as if StreamingEnabled is disabled?)

I am aiming for my doors to open and close which ever way is most optimized, so if you have any other ways or suggestions then let me know!

If you would like to make an example file then that would be greatly appreciated but an explanation works just as well!

I’m sorry that I made this post so long! It took my over 30 minutes to write this, but please read all of this post as there may be some hidden important parts that you may need to read!

Thanks, any help appreciated!

9 Likes

None of these options are any good.

Use a Proximity Prompt and move the door on the server.

Doing fire all client’s causes anyone out of the streaming radius to receive this data but be unable to do anything with it.

May I ask, where did you receive this misinformation?

4 Likes

I’m not sure if you read all of the post but, if you read this paragraph wouldn’t this mean streaming enabled is disabled on the door model so it would basically be in the clients world the entire time?

I’ve viewed this information multiple places on the Devforum. A couple people said that its better to open/close the doors on the client as it’ll give the server less worth and no latency or something.

3 Likes

Disabling streaming is the least optimized way to do it, it is the definition of the most in-efficient way to do things.

Moving it on the client vs using TweenService has virtually no difference. TweenService uses prediction, the client will predict the movement, it will move extremely smooth. Using any other method on the server-end (such as CFraming it) will cause latency.

3 Likes

Well, I mean just disabling streaming on the door model, not the entire game.

To me, having to create a tween for each door just makes things look messy and ugly. I have no idea why I’ve seen multiple posts that say it is better to animate the door on the client or server, I’m not really good at optimizing things but I’m currently trying to learn optimization. I’m not really good at the whole benchmarking, micro profiler, dev console performanty stuff. I suppose I could try multiple different ways to see what’s best even though I’m too lazy for that lol. But I’ll just see what other devs have to say.

1 Like

Here are a few posts that say its better for the client to handle the opening/closing of a door.

1 Like

You don’t need to create multiple Tweens. You can reuse the same one, and call :Play on it multiple times.

1 Like

That’s what I did when I was using tweens, but what I meant was if I have to create new tweens for each door object, where is, I can just assign a door to a function that opens or closes the door.

1 Like

You can do the same with Tweens, you can put the Tween data in a function.

1 Like

But it is still creating another tween for each instance. You can’t use one tween for multiple different instances you can only use one tween per instance.

I’ll attempt my own little test to see what is better, you’ll hear from me within a week about the test.

Yes, you can. A Tween can move an entire assembly. By combining a Tween and using PivotTo, or using constraints like a HingeConstraint with rigidity enabled.

I have no idea what you mean. Could you write a quick example?

I should mention, this specific door is for a train so its basically 2 sliding doors that split apart when they open if you know what I mean.

local door = workspace.Door
local nv = Instance.new(“CFrameValue”)
nv:GetPropertyChangedSignal(“Value”):Connect(function()
door:PivotTo(nv.Value)
end)
TweenService:Create(nv,TweenInfo,{Value = …})

1 Like

The door is welded to a main part and the main part tweens with the door which worked fine, so I don’t know if that’s what your codes doing but instead moving the whole model without a main part

1 Like

For the question one, you can use the good old clickDetector or proximity prompt and use tweenservice to make the door slide or even rotate on a precise angle. If the door have multiple part for details, simply add another part to the model, make it anchore then weld it to every other parts of the door that you’d like to move with it, then once that’s done, unanchore other parts exept the hinge. Just need to tween the hinge part of the door and you’re good to go.

The door is a sliding doubled sliding door (Train door that splits when opening). The door lerps when opening or closing, but the question is, is it more performant on the client side or on the server side.

I’ve performed my own little test, and it seems to be that animating the doors on the client is a lot better and smoother than animating the doors on the server. I will perform some more tests and update this post with the result.

1 Like

On the client side it will always be more performant since the action is similar to moving ur character, it’ll be very smooth but for you only. However, using this will cause other player to not be able to see the door open and they will see the client pass trough the door.

Basically, if you seek smoothness do it from client event, but if you want everyone to be able to see these animations then do it on a server script. If the server doesn’t have lot of ping it should be smooth enough.

Well, what’s the catch if I make it so once a player clicks a gui button on their screen and it fires a server event that’ll fire the open door event for all clients?

Basically,
ButtonClicked > FireServer (Does some checks to see if the door is allowed to open) > FireAllClients (Opens door on client)

Oh wait- maybe that’s a good idea, I never tought of that. Ur bright my guy. Try that and tell me how it’s working!