Sound is playing more than once

I want a sound to play once if the armor gets lower than 10, but whenever it gets lower than ten, the sound plays multiple times. Here’s my code.


 if armor < 10 then
		 ply:sound.Play("ui/low.wav")
	  end 


Is there a way around this? I’d appreciate your help.

Is this clientside or serverside code?

clientside

That’s not proper code and should error. sound.Play doesn’t take a player argument like that.

How about this?


 if armor < 10 then
		 ply:EmitSound(Sound("ui/low.wav"),72,100)
		
	end


It still seems to be overlapping, unfortunately.

What happens if you comment out the emitsound?

perhaps try
[lua] if CLIENT then
if armor < 10 then
ply:EmitSound(Sound(“ui/low.wav”),72,100)

end

end
[/lua]
idk maybe the sound is playing server side aswell

Are you running this inside of a hook? If so what hook?

I am, here’s the hook:


hook.Add("PlayerHurt","SES.Hooks",function(ply,att,hp,dmg)
	ply.ses = ply.ses or {}
	ply.ses.Regen = 0
	local armor = ply:Armor() --CACHE FUCKING
	if CLIENT then
		if armor < 10 then
		 ply:EmitSound(Sound("ui/low.wav"),72,100)
		end
	end 
	if armor == 0 then
		if ply.ses.Full == 1 then
			local effectdata = EffectData()
			effectdata:SetOrigin( ply:GetPos() )
			effectdata:SetEntity(ply)
			util.Effect( "plasma_boom2", effectdata )
			ShieldDown(ply:GetPos()+Vector(0,0,30),25)
			--ply:SendLua("surface.PlaySound('ui/shieldstop2.wav')")
			ply:EmitSound(Sound("ui/shieldstop2.wav"),72,100)
			ply.ses.Full = 0

		end
		ply.ses.HPAMT = ply:Health()
	elseif armor > 0 then

		local effectdata = EffectData()
		effectdata:SetOrigin( ply:GetPos()+Vector(0,0,30) )
		effectdata:SetEntity(ply)
		util.Effect( "shieldHit", effectdata )
		if dmg < 22 then
			ply:EmitSound(Sound("ui/shield/light/hit1.wav"),72,100)
		elseif dmg >=22 and dmg < 66 then
			ply:EmitSound(Sound("ui/shield/medium/hit1.wav"),72,100)
		elseif dmg >=66 then
			ply:EmitSound(Sound("ui/shield/heavy/hit1.wav"),72,100)
		end
		if ply.ses.Notif > 0 and ply:Armor() <= 28 then
			ply.ses.Notif = 0
		end
		ply:SetNWFloat("ses.Recharge",5)
		ply:SetNWFloat("ses.TookHit",4)
		ply.TickTime = CurTime()
		ply:SetHealth(ply.ses.HPAMT)
	end
	timer.Remove("ses_ply"..ply:Nick())
	timer.Create("ses_ply"..ply:Nick(),8,1,function()
		if !IsValid(ply) then return end --Player Disconnected
		ply.ses.Regen = 1
		ply.ses.Full = 1
		ply.ses.Notif = 1
		ply:EmitSound(Sound("ui/shieldstart1.wav"),72,100) --...
	end)
end)


Actually, this code does seem like it’s for serverside. This is code from the Simple energy shield addon, I’m just adding a low shield sound.