Should i keep it client or server

Hello, I’m creating a Physical Spinning system. I’m just wondering what is the best way to display what the player is rolling without causing lag, as the major feature of the game will be rolling for items. How would I go for this without causing lag? I am using Tweens to make this function too

Any help would be helpful!

3 Likes

I assume this is something similar to a case-opening system?
If so, you want to have the server already know what the player rolled, and then display an animation of that on client.
What do you mean by this?

2 Likes

do it like in server authority
Server validates, client interprets

4 Likes

Like within Rivals the player opens a case and it display that unboxing case for all players, I just want to understand how to optimise it for all players within the game when the case opening system is rolling, I’ve seen other games make the Tweens laggy when they are far away

1 Like

You could on the server pick the reward they get, then send that to the user and all players within like 30 studs. So, if you’re within 30 studs of the case, you get the remote event fired for yourself, and your client plays the animation. Also, for the player it is meant for, you could pass in an extra variable to tell them it’s their prize.

That way clients are the ones playing the animations, and only if they are < 30 studs. Also this means all other players can see it too.

1 Like

Like @LxckyDev mentioned, fire a RemoteEvent for every player within a certain distance and parse a table with the data that the client needs through. The data should contain the recipient (for example because their client will simulate a popup on their screen), and also the prize that they received. The rest can likely be simulated unless you have more detail on the crate that needs to be passed with the event

2 Likes

Hey! To avoid lag with a spinning or rolling system, the golden rule is to do all the heavy visual animation entirely on the Client (LocalScript) while the Server handles the RNG (Random Number Generation) and data saving.

Here is the best approach:

Server-side: When a player clicks spin, the server rolls the item using something like this:

local Random = Random.new()
local min = 1
local max = 100 - - For example
local number = Random:NextInteger(min, max)
print(number)

or a weighted table, saves the result, and fires a RemoteEvent to the client telling them what item they won.

Client-side: Once the client receives the winning item, it plays the smooth visual spin (using TweenService or RunService) stopping precisely on that item.
Since you mentioned Tweens, using TweenService on the client for GUI elements or parts is totally fine and lightweight, as long as you aren’t doing complex physics calculations on the server for every single player’s spin.

1 Like