First Person Shooter Help

One big problem I face is regarding client server replication: how can I minimise the load onto the server with remote events firing so many times? With automatic guns, it eventually reads to the remote event queue filling up, and of course dropping the requests. Is there any way to avoid such a thing?

Another problem is that I tend to have is that I am not exactly sure how to structure the project… should I use a client sided viewmodel class which uses methods to load guns in (no client sided weapon class), or should the weapons have their own classes too? Both methods seem either difficult to customise or difficult to implement, and this has been bugging me for probably years now lol

Any advice on FPS systems is really appreciated

Use UnreliableRemoteEvents for this type of thing. Unreliable remote events usually are faster than remote events, but they may not fire if the server is “burning out” (hence the name Unreliable).

Take a look at it here. In this case, you could use unreliable remote events for when the player presses the mouse button; then, the server replicates the gun shooting, so everyone can see it. You can add debounce so it doesn’t fire multiple times and overload the server.

EDIT: Additionally, if you need to do some math accounts (which likely you would need to), do it locally, not on the server. Just use the server for replication.

1 Like

Regarding how to make guns classes, I recommend you learn OOPs. The way you make yours is up to you, I can’t help much with it. However, you can create a module script that handles the creation of guns. For instance:

local guns = {}
guns.__index = guns
    
function guns.New(gun: string, information : {Ammo : number, Damage : number})
    local self = {}

    self.Name = gun

    for name, value in information do
        self[name] = value -- Creates indexes inside self representing the information parameter (self[Ammo] = number, and so on)
    end

    return setmetatable(self, guns)
end

function guns:Shoot()
    if self[Ammo] == 0 then 
        print("No ammo!")
        return 
    end

    self[Ammo] -= 1

    unreliable:FireServer() -- Fires the server, and there you can make the actual gun shooting...
end

return guns