Intentionally Delayed Bullet Firing Twice on Servers

Hi again users of Facepunch.
While working on a small SWEP, I ran into a bit of a problem.

I have it so when I do my PrimaryAttack Function, a bullet is fired two seconds later thanks to a timer.
On singleplayer this works absolutely fine, however, on multiplayer, it seems to fire two bullets.
Just like the bullet firing twice, my PrimaryAttack sound also seems to play twice.

[lua]timer.Create( “Attack” … self:EntIndex(), 2, 1, function()
local trace = self.Owner:GetEyeTrace()
if trace.HitPos:Distance(self.Owner:GetShootPos()) <= self.Primary.Range then
local bullet = {}
bullet.Num = self.Primary.NumberofShots
bullet.Src = self.Owner:GetShootPos()
bullet.Dir = self.Owner:GetAimVector()
bullet.Force = self.Primary.Force
bullet.Damage = self.Primary.Damage
bullet.AmmoType = self.Primary.Ammo
self.Owner:FireBullets( bullet )
self.Owner:EmitSound(Sound(self.Primary.Sound))
end
end)[/lua]
To further test the issue, when inserting a "print(“Test”) statement within the timer, test is printed to console twice.


Test
Test

Basically, anything within PrimaryAttack that is delayed with a timer is ran twice on multiplayer.
Is this an issue involving CurTime() somewhere?
Any advice is appreciated. :smile:

Try

IsFirstTimePredicted

I added [lua]if not IsFirstTimePredicted() then return end[/lua] right under my timer and that fixed the issue. However, I also have another sound that is emitted by the Owner of the weapon within PrimaryAttack outside of the timer, which still seemed to play twice. The solution? I added “if (SERVER) then” above it and now the sound only plays once.
Thanks so much for the help. :happy: