Yep, I'm in desperate need right now after solving the last problem. A new problem has spawned, and that the bullet inflicts the user even though it's not shooting at itself. I set the user itself and its humanoid at the ignore lists, but even though, it just keeps on killing itself.
--DEFINING--
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local bullet = ReplicatedStorage:WaitForChild("7.62x51mmNATO")
local user = script.Parent
local sound = user.gun.Firesound
local casing = ReplicatedStorage:WaitForChild("shellEject")
local hrp = user.PrimaryPart.Position
local hrpnp = user.PrimaryPart
local gun = user.gun
local br = gun.barrel
local human = nil
local torso = nil
local fireRate = 0.1
local bulletSpeed = 200
local aggroDist = 50
local dmg = 10
print ("succesfully loaded all terms")
--FIRING--
while wait(fireRate) do
local target = nil
for i, v in pairs(game.Workspace:GetChildren()) do
human = v:FindFirstChild("Humanoid")
torso = v:FindFirstChild("UpperTorso")
if human and torso and human.Health > 0 then
if (torso.Position - hrp).magnitude < aggroDist then
local bulletRay = Ray.new(hrp, (torso.Position - hrp).Unit * aggroDist)
local hit, position = game.Workspace:FindPartOnRayWithIgnoreList(bulletRay, {script.Parent, script.Parent.Humanoid})
if hit == torso then
target = torso
else
target = nil
end
end
end
--GUN MECHANICS--
if target then
torso = target
user:SetPrimaryPartCFrame(CFrame.new(hrp,Vector3.new(script.Parent)))
hrpnp.CFrame = CFrame.new(hrp, torso.Position)
local newBullet = bullet:Clone()
local fire = sound:Clone()
fire.Parent = gun
newBullet.Position = hrp
newBullet.Parent = workspace.Camera
newBullet.Velocity = br.CFrame.LookVector * bulletSpeed
newBullet.Touched:Connect(function(objectHit)
local human = objectHit.Parent:FindFirstChild("Humanoid")
if human then
human:TakeDamage(dmg)
wait(1)
newBullet:destroy()
else
human = nil
end
end)
end
end
end
