So I have gone through a tutorial on how to make guns, due to me having no previous knowledge, and now that I know a bit more, I managed to rummage through and modify it, make it better, my problem now is, the guns are very laggy…
Local Script:
Server Script:
Any advice on reducing lag would be appreciated!
You can see the lag and see what I mean by trying the guns here:
The more people shooting, the more chaotic the lag.
In the loop in the tool.activated function on line 156 in your local script it has a wait(0). That is running the fire() function too fast, it should be at least a 0.01 wait before calling the fire function again.
The difference between wait(0) and wait(.01) is miniscule as wait(0) defaults to wait() which is roughly every 1/30 seconds (or roughly .03), and so calling wait with .01 as an argument is pretty much redundant.
My bad. For some reason I thought wait() just yielded until everything above was done.
Anyway, awhile back I used the same scripts as @aerophobes is using now but I modified them a bit as well (added crosshairs, mobile support, preventing team kills, etc.) and I had a wait(0.01) and my fire rate in the configure folder was set to 300. With these settings I had no noticeable lag. If @aerophobes is interested I can show my scripts.
I’ve had this problem too to the point where my Roblox crashed.
Replace your repeat until loop with the RunService.RenderStepped event, like this:
local runService = game:GetService("RunService")
runService.RenderStepped:Connect(function()
if(mouseDown) then
-- do the shoot stuff here instead
end
end)