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)