Any way to have a script ONLY run on the server and not replicate to the clients?

The reason I need this is because I’m creating a 3D spinner wheel. On the server, the wheel gets spun and eventually slows down and then gets a range of orientation for what it landed on. However, while spinning it looks choppy for the client. I don’t want a server and client script running the same thing either (I know it’s not a great idea) since it interferes with the movement on the client. The server spin of the wheel is used for data, while the client side is used for just display since its smoother.

1 Like

what are you using to spin the wheel

like are you using constraints, alv, what u doin

1 Like

A really simple solution is interpolation. Have the client make a copy of the wheel, and make the original one invisible (without destroying it), then use TweenService to continuously smoothly rotate the client wheel to match the server wheel.

Then, once the wheel stops spinning, destroy the client wheel and make the server wheel visible again.

We could optimise this further, however. If it doesn’t matter much if someone can know what the wheel will land on a few seconds before everyone else, you can have the server tell the clients what the wheel will land on, then have the clients move the wheel instead, and reach the target in the same amount of time across all the clients.

4 Likes

This is because anything does on the server must replicate to the client. A good general rule of thumb to go by is that for animations, effects or other visual enhancements, always run this on the client. Switching the spin animation from the server to the client would fix this issue and be significantly more performant.

Heres a layout that I have personally used on a wheel system I created for a commission!

Server

  • Handles calculating the end result with win chances, look in to the Weighted Random Algorithm or use open sourced modules such as LootPlan
  • Opens an exposed endpoint, using a RemoteFunction, which when called to will return a random result using the algorithm above
  • Run checks to make sure the user is eligible to spin (e.g. Charge them a currency, check if they have spins left)
  • Award the player whatever the result was

Client

  • When ready to spin, have the client call the RemoteFunction you made earlier, and if it replies with a valid response then start an animation.
  • Make an animation (either with TweenService or with a RunService loop) that will spin the wheel however you like it. In your case, you can likely just copy this code from the server and make a few small changes!

If you are wanting the wheel to run for all clients, then you could try replacing the RemoteFunction with a RemoteEvent and running Remote:FireToAllClients() when the result is chosen by the server.

Hopefully this gave you some decent insight on client-server relationships

1 Like

Actually awesome and simple idea.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.