I am making a module script to handle bullets being shot. It handles the tracers, hit registration, etc.
I want hats to be ignored by the gun. And also ignore the player shooting the bullet.
But I cant add the character to the ignore list without it making the player invicible.
I am out of ideas of how to fix this at this point.
If you can help me that would be cool thx.
local module = {}
--[[=Variables=]]--
local Debris = game:GetService("Debris")
local ig = {workspace.Ignore}
local playSound = function(name,part,shift)
local Sound = script.Sounds:FindFirstChild(name):Clone()
Sound.Parent=part
Sound:Play()
Debris:AddItem(Sound,3)
end
local makeEffects = function(stat,mpos,hole,part,normal)
local Beam = stat.Beam or script.Beam:Clone()
Beam.Parent=hole
local AttPart = Instance.new("Part",workspace.Ignore)
AttPart.Size=Vector3.new(1,1,0.05)
AttPart.Position=mpos
AttPart.CFrame=CFrame.new(AttPart.Position, AttPart.Position+normal)
AttPart.Transparency=1
AttPart.CanCollide=false
script.BulletHole:Clone().Parent=AttPart
local Att1 = Instance.new("Attachment", AttPart)
Att1.WorldPosition=mpos
local Att0 = Instance.new("Attachment", hole)
local Weld = Instance.new("WeldConstraint", AttPart)
Weld.Part0=part
Weld.Part1=AttPart
Beam.Attachment0=Att0
Beam.Attachment1=Att1
Debris:AddItem(AttPart, 2)
Debris:AddItem(Att1, 2)
Debris:AddItem(Weld, 2)
Debris:AddItem(Att0, 0.2)
Debris:AddItem(Beam, 0.2)
end
module.raycast = function(stat,origin,mpos)
local rayParams = RaycastParams.new()
rayParams.FilterType = Enum.RaycastFilterType.Blacklist
rayParams.FilterDescendantsInstances = ig
rayParams.IgnoreWater = true
local rayResult = workspace:Raycast(origin.Position, (mpos-origin.Position).unit*stat.Range, rayParams)
if rayResult then
if not rayResult.Instance.Parent:IsA("Accessory") then -- Make sure its not a hat.
local hitPart = rayResult.Instance
local humanoid = hitPart.Parent:FindFirstChild("Humanoid")
makeEffects(stat,mpos,stat.hole,hitPart,rayResult.Normal)
if humanoid then
playSound("Human",hitPart)
local Blood = script.Blood:Clone()
Blood.Parent=hitPart
Blood.Enabled=true
Blood.Script.Disabled=false
game:GetService("Debris"):AddItem(Blood,1)
if hitPart.Name=="Head" then
humanoid:TakeDamage(stat.HeadDamage)
else
humanoid:TakeDamage(stat.Damage)
end
end
else
table.insert(ig,rayResult.Instance)
module.raycast(stat,origin,mpos) -- Redo raycast.
end
end
stat=nil
origin=nil
mpos=nil
rayParams=nil
rayResult=nil
end
return module