while shooting do -- Automaticly
local ammo = ReplicatedStorage.Fire:InvokeServer({Origin = workspace.CurrentCamera.CFrame.p, Direction = mouse.Hit.LookVector}) -- Raycast in server
if not ammo then return end
task.wait(0.05)
end
Not a solution, but I’ll just share something I’ve heard which I think is the issue. The invokeserver part. When you’re in studio, the server is run by your device, so the signal takes no time to be send from your client to the server and then back. But in-game the servers is no longer run by your device but by Roblox’s servers somewhere in the US. So that means you’re sending a signal to their servers back and forth every .05 seconds accross the world and it can’t keep up.
Sorry for long reply.
I suggest rendering a “fake client” bullets into your client.
Then, create a bullet to the server that handle the damagin part.
Then, render the client bullet to the others
Studio is hosted locally, meaning you have 0 ms ping, however, inside of ROBLOX you are connected to a server that is in a different region or country, your wifi will connect to that server and that will give you a latency depending on how far away you are (such as 100 ms).
So in conclusion this is a regional problem, you can fix that easily by buying flight tickets worth more than 100 bucks and fly to calafornia or florida where most of the ROBLOX servers are kept.
Basically, Invokeserver waits until it gets a response from the serverscript. If a player has high ping, it will wait longer.
In studio, the server is hosted locally so you will instantly get a response from a remotefunction, but ingame, it will be hosted somewhere on a roblox dedicated server which is farther away from your actual computer, so it will wait for longer before it gets a response from the serverscript.
If you want it to be the same for all clients, run the ammo calculation locally and use a remoteevent instead, then you could have an ammo value somewhere (maybe in replicatedstorage? it doesn’t matter, it is all up to your preference.) to sync the client with the server.
Everything said previously is true and needs to be thought about but another change you can make is to use a RemoteEvent rather than a RemoteFunction.
A RemoteEvent is one way so you don’t have to wait for a response from the server.
I’d also recommend setting your Ammo to a NumberValue or Number Attribute that the server can change.
You can then check that value from the client and use a Changed event if you need to see when that value changes.
(You can change the Ammo client side as well. This will stop the Client from shooting before the server updates the ammo count correctly. Then once the server updates the value it will be synced back up)
RemoteEvents don’t wait until the server gives a response, but you also can’t send data back to the client through a remoteevent like you can with a remotefunction.