Log in to vote

What are some tips on optimizing a gun system?

Asked by 13 days ago
Edited 13 days ago

To not bore you people with the details, I'm working on a gun system with a server sided script in server-script-service. The issue is that traces occasionally just refuse to appear. The way the gun system works is that there is a single remote-event in replicated-storage, that event is fired by all the guns when being shot. Also, bare with me because I'm somewhat new.

Also, keep in mind that the server-sided script in server-script-service handles the shooting, damage handling and playing audio when reloading, which is why you see the "If not IsReloading then" line is there.

So, basically, my question is what are some ways of optimizing the gun system.

Example of the remote:

ShootRemote.OnServerEvent:Connect(function(player, tool, traceColor, mousepos, position)
    if not IsReloading then
        local ShootSound = tool.Handle:WaitForChild("Shoot")
        local MuzzleFlash = tool.Hole:WaitForChild("MuzzleEffect")
        local Hole = tool:WaitForChild("Hole")

        MuzzleFlash.Enabled = true  

        local trace ="Part")
        trace.Anchored = true
        trace.CanCollide = false
        trace.Transparency = 0.8
        trace.BrickColor = traceColor
        trace.Material = Enum.Material.Neon

        local distance = (Hole.CFrame.p - position).magnitude

        trace.Size =, 0, distance - 2)
        trace.CFrame =, mousepos) *, 0, -         distance/2)
        trace.Parent = workspace

        MuzzleFlash.Enabled = false


Answer this question