Help creating a gun system with a singular server script

I am trying to achieve a gun system using one server script in ServerScriptService and one client script per gun. I already have a good idea on how to use ray casts and remote events, I am just unsure on where to start.

My main curiosity is what script will I do the ray cast on and how will I ensure the gun system is secure?

Here is an image for a good idea on what I want to create:

I have created gun systems that use the server script inside the gun in the past already.

Many games actually use a server script in ServerScriptService and make the guns have client scripts and their gun systems are great. I know there is a way to do it without bugs, I am just unsure how.

No it won’t.

Have the client send the server a signal when a player tries to fire, reload, etc. Have the server keep track of each client’s ammo, time since last firing, etc. The server needs to verify that the client can shoot to make sure exploiters cannot abuse the system (you might want to also do a check on the client). The server handles the shot, damage to others, etc. and lets clients know what happened.

Take this with a grain of salt, I’ve never scripted a gun before.

Even though you have already solved this, what I would do is:

1. Create a script on ServerScriptService that goes like this

game.Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Character)
     Character.ChildAdded:Connect(function(Tool)
              if Tool:IsA("Tool") then
                local activatedConnection
                activatedConnection = Tool.Activated:Connect(function()

                 -- Fire a remote to client saying that they can now fire and render the bullet
                 -- on the client, send another remote with the **CAMERAS LOOKVECTOR** NOT
                 -- Mouse.Hit because it is inaccurate.
                 -- This code is only an example, if you want more reply to this comment

              end)

              Tool.Unequipped:Connect(function()
              if activatedConnection then
                  activatedConnection:Disconnect()
                  end
              end)
           end
       end)
    end)
end)

Normally I would prefer doing rendering on the client, but this is almost necessary for a game with a lot of guns/customization, because the traditional client-sided system is easy to exploit.

(Unless you do it well)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.