I’m trying to make a level-based game that implements boxes that the players can interact with. There will be multiple different stages running in a single server with different “teams” of players working together on each stage. To save resources, I want to make the game mostly client sided, with the server predominately used for interaction between clients and of course anti-exploit checks.
Currently, I have a working box script, but its just a single client interacting with the server. This is how it works:
- All of the boxes exist on the server. These are unachored so players can push them around.
- A player walks up to a box. Their client picks it up by clicking on the box (UserInputService on MouseButton1).
- The client clones the box, and every heartbeat the box location is determined by raycasting from the player’s head to the mouse position.
- The cloned box is moved to that position with BodyMovers
- Every 5 heartbeats, the current target box position is sent to the server, in which the server box is moved to that position again with BodyMovers.
- The player releases the box. The clone is destroyed, and they see the real box again.
Here is a short clip of it working: https://streamable.com/no542x
As shown in the clip, I need the boxes to interact in certain ways:
- Pushed by walking into it
- Have buttons detect them (currently done on server by checking a Region3, but I may need to adopt it to the client)
- Be carried by moving platforms (The platforms are tweened, and the box is moved by raycasting downwards, and if the platform is found the box will move with it)
There’s really a lot to do here, and I don’t really know where to begin. I’ve tried creating clones of the box on all clients when one client picks it up, and teleport the [anchored] server box’s CFrame to the target position, but I’m running into problems with physics as the box should fall when released, but the server box won’t do that. I’ve also had the problem of clients seeing the boxes rest in different positions as they will bounce differently when they fall.
I haven’t really attempted to do something like this, so I don’t know the proper way to go about this. Should boxes even exist on the server, even if they’re hidden? How could I make sure all clients see the box in the same position?
Basically, how can I do something heavily physics based entirely on the client, using the server just as a means of communication?