I am trying to make a gun that fires single bullets (instead of rays) even though filteringenabled is on. There is a problem in the localscript that makes the rest of the tool stop working. I have based my script on StickMasterLuke's tutorials on how to make a Net Gun, but it seems like it doesn't fire my function when it is called upon. Here's my LocalScript
local tool = script.Parent local event = game.ReplicatedStorage:WaitForChild("RemoteEvent") local firesound = tool.Handle:FindFirstChild("FireSound") local reloadsound = tool.Handle:FindFirstChild("ReloadSound") local maxammo = tool.Configurations.MaxAmmo.Value local ammo = tool.Configurations.Ammo.Value local attackcooldown = tool.Configurations.AttackCooldown.Value local reloadtime = tool.Configurations.ReloadTime.Value local range = tool.Configuration.Range.Value equipped = false canfire = true reloading = false function checkintangible(hit) if hit and hit~=nil then if hit:IsDescendantOf(tool.Parent) or hit.Transparency>.8 or hit.Name=="Handle" or string.lower(string.sub(hit.Name,1,6))=="effect" then return true end end return false end function castray(startpos, vec, length, ignore, delayifhit) local hit, endpos2 = game.Workspace:FindPartOnRay(Ray.new(startpos ,vec * length), ignore) if hit~=nil then if checkintangible(hit) then hit, endpos2 = castray(endpos2+(vec*.01),vec,length-((startpos-endpos2).magnitude),ignore,delayifhit) end end return hit,endpos2 end tool.Equipped:connect(function(mouse) --this doesn't fire equipped = true if mouse then mouse.Icon = "rbxasset://textures\\GunCursor.png" mouse.Button1Down:connect(function() local humanoid = tool.Parent:FindFirstChild("Humanoid") local head = tool.Parent:FindFirstChild("Head") local torso = tool.Parent:FindFirstChild("Torso") if canfire and ammo >=1 and not reloading and humanoid.Health >= 1 then firesound:Play() canfire = false local character = tool.Parent local vec = (mouse.Hit.p - head.Position).unit local hit ,endpos = castray(head.Position, vec, range, tool.Parent) event:FireServer("Fire", endpos, hit) wait(attackcooldown) canfire = true elseif ammo <= 0 then canfire = false event:FireServer("Reload") wait(reloadtime) canfire = true end end) end end) tool.Unequipped:connect(function() equipped = false end)
I thank you for any help in advance! :))