Need help with some lua

This is intended for DarkRP, but the gamemode is irrelevant tbh.

I need help coding a C4 Defuser to work with Mad Cow’s C4. All I need to do is identify that the object being looked at is mad cow’s c4, and i need a way of removing the targeted entity, and also playing a sound. The actual code Ill compile for a server (and of course anyone who assists will get credited in the source code)

Use a more specific title next time.

SWEP.Primary.Sound = “sound/mysound.wav”

function SWEP:PrimaryAttack()
local eyeTrace = self.Owner:GetEyeTrace()
local distance = self.Owner:EyePos():Distance(eyeTrace.HitPos)
local ent = eyeTrace.Entity
if distance <= 75 and IsValid(ent) and ent:GetClass() == “ent_mad_c4” then

Coded on a phone. May or may not work.

sweet. Ill try that when i get home (also on phone). I was intending on tieing it with the lockpick so it has a timer and plays a “Bomb defused” sound afterwards but your code made me think: “Why not have it say ‘Defusing’ when you start?” lol.