How would I make a gun fire with the shortest delay possible?

I have made a revolver for a game. It is fairly simple. The client sends mouse position to the server. While playing the game in Roblox, the time between clicking and the gun firing is approximately 0.5s, which is just too much of a delay. What should I do to decrease this delay, as obviously, other games have guns that fire instantly. I find the revolver from the game Murder Mystery 2 has a similar delay but not as significant.

--> CLIENT
Gun.Activated:Connect(function()
	if not Reloading then
		Reloading = true
		local Mouse = Player:GetMouse()
		Gun.Events.Bullet:FireServer(Mouse.Hit.Position)
		if Mouse.Target.Parent:FindFirstChild("Humanoid") then
			Victim = Mouse.Target.Parent
		elseif Mouse.Target.Parent.Parent:FindFirstChild("Humanoid") then
			Victim = Mouse.Target.Parent.Parent
		else
			Victim = nil
		end
		local ShotMurderer = false
		if Victim ~= nil then
			if game.Players[Victim.Name].Team == game.Teams.Murderer then
				ShotMurderer = true
			else
				ShotMurderer = false
			end
		end
		Gun.Events.Fire:FireServer(Victim, ShotMurderer)
		if FastReload == true then
			wait(2)
		else
			wait(3)
		end
		Reloading = false
	end
end)

--> SERVER
Gun.Events.Fire.OnServerEvent:Connect(function(Player, Victim, ShotMurderer)
	GunHandle.GunFire:Play()
	if Gun.Name == "Revolver9" or "Revolver10" then
		GunHandle.GunReload:Play()
	end
	if Victim ~= nil then
		Victim.Humanoid.Health = 0
		if ShotMurderer == true then
			local HitSound = GunHandle.GunHit:Clone()
			HitSound.Parent = Victim.Head
			HitSound:Play()
			local WinParticles = Gun.WinParticles:GetChildren()
			for i, v in pairs(WinParticles) do
				v.Parent = Player.Character.Head
				v.Enabled = true
				wait(.1)
			end
			wait(1)
			for i, v in pairs(Player.Character.Head:GetChildren()) do
				if v.ClassName == "ParticleEmitter" then
					v:Destroy()
					wait(.1)
				end
			end
			wait(10)
		else
			Player.Character.Humanoid.Health = 0
		end
	end
end)

use to make it the shortest delay

wait()

Where and why? A little more specific?

EDIT: I haven’t used any wait() during the firing process, only for reloading and when a specific person is shot. I don’t think you understand what I’m saying

wait() is depreciated. task.wait() should be used instead for future projects. It is much more accurate and if used with no arguments, it will delay for exactly one step.

1 Like

I personally dont think we can do much about the delay except make it look like the weapon was shot.

Usually games would do is handle the visuals and sounds on the client (e.g. creating particles, muzzles, weapon fire sounds, weapon hit sounds), fire an event to the server to handle damage and the important features of the weapon, then playback the sounds and visuals to every player except the one who already shot the weapon

1 Like

I see, thanks for that! I’ll definitely change some aspects

Are you talking about the gun fire/bullet effect, or bullet effect being delayed?

If so, you could make the gun fire, or bullet effect effect be client side for the gun user for instantous effect, but also fire the RemoteEvent to do something like making gun fire, or bullet effect be seen by other players.

1 Like

Unless you expect everyone to have low ping or the game have bullet drop, do the bullet calculation on the client.

The security given by doing it on the server is not worth the lost of user experience.

Yep that’s what I’m working on right now and as @UltraAGENTYOUTUBE said earlier

There are better, although more complex, ways of handling this without compromising security. For one, “rapid fire” weapons don’t actually need to calculate every singe bullet. Groups can be done at a time. Secondly, you can use Rollback Netcode to deal with the delays.

1 Like