This is my first time, and I’m in need of advice of a plan on how it should work.
E.g: Client asks the server to fire a bullet, server handles ammo and stuff, decides if it can fire the bullet and then lets that replicate to the other clients. Problem with this is that automatic guns would be out of time unless you have perfect ping. Their are flaws in most methods I’ve thought of, just need to know from someones past experience the best way to go about.
Things like storing bullets in the mag and stuff, would I just use tables? Using number values in tools and such will probably just help exploiters.
Other question is that I plan to use raycasting to do bullets because adding bullet drop and speed etc wouldn’t work well. Any advice on doing this and the best way to hold back exploiters from it?
Anywho, Personally speaking I would handle all of the mechanics on the client. The only thing the server would do is verify if a hit was possible at the time of the request. Even better if I could include HSR (Host State Rewind). The player should always feel the feedback near instantly. They shouldn’t have to shoot the gun and wait several seconds to see their bullets or even see the hit take effect. Applying damage however will have a delay. I’m not sure if there’s a way around that. I haven’t been able to get past the “Fake Arms” part of gun mechanics so I wouldn’t be the best person to give a response to this thread.
To ensure people don’t exploit their gun stats you need to set a script which has the gun stats as constants and if the value changes you kick the player. Hope I helped.
Yes, but that would have to be on the client, which an exploiter could still mess with.
Things like how often a bullet can be fired, ignore lists and stuff and stopping them from shooting players across the map would be hard to deal with I think.
You could make a loop which every x seconds it changes the variable values to the same old value and make it serversided so that if someone changed the value in some way and its a serversided change his gun will switch back to normal and will probably annoy him and stop him from trying to exploit your gun.
There is no such thing as “Perfect” when it comes to this stuff unfortunately. If i were you i would have the client ask the server to fire a shot(s). Send that to the server, validate the args (Is the origin of the shot close to the shooter?) and store that shot in a table until they shoot again (You will want to store it on the client too). Here you can also store ammo and what not and just subtract what you need when they shoot as well as verifying the rate of fire. Reloads are also something you will want to do on the server. You can always do these checks on the client as well to prevent unneeded firing of remotes by normal players.
When it comes to validating a hit you can just tell the server what object you hit and the shot object you hit them with. Remember this is also stored on the server so you can easily check the validity of the shot using Shots[Player]. Because we have that shot safe we should be able to assume that its okay to use when validating a hit as we already verified the shot. This might sound kind of confusing upfront so I’d reccomend you check out [OS Game] Ruddev's Battle Royale Open Sourced as it can give you really good insight on validating shots and hits on the server in a relatively efficient way. There is a script called “GunScript” located in ServerScriptService > ItemHandlers.
You will see how they store each shot on the server along with the position it was shot at and the direction (or directions if its a shotgun) were fired in.