I was trying to make some enemy script that shoots you, but I keep stumbling across this problem.
I don't know what's happening but, what I know is that the bullet checks if what they hit has a humanoid in it. If they shoot nowhere, that's when the script will halt.
I have no way how to find every humanoid and how to use it in the bulletHit's argument.
I have lost my insanity especially it's now near midnight so I decided to give up and complain about it instead.
Perhaps I might reverse-engineer the lava brick cus the things these two in common is to damage the player.
--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 and human.Parent.Name ~= "hg" then
human:TakeDamage(dmg)
wait(1)
newBullet:destroy()
else
human = nil
end
end)
end
end
end

2 comments
What line is the error at?
line 56, wheareas the script tries to index/find if there's a humanoid in what they have hit