Every few seconds a new part is created and when the part gets touched via a touch event it damages the player. Sometimes the touch event triggers without the player touching the part.
This is the code:
local bulletPart = Instance.new("Part")
bulletPart.Parent = workspace
debris:AddItem(bulletPart, 0.1)
local distance = (target - bulletPos).Magnitude
bulletPart.Size = Vector3.new(0.1, 0.1, distance)
bulletPart.CFrame = CFrame.new(target, bulletPos) * CFrame.new(0, 0, -distance/2)
bulletPart.Anchored = false
bulletPart.CanCollide = false
bulletPart.Transparency = 0
bulletPart.Material = Enum.Material.Neon
bulletPart.Touched:Once(function(otherPart)
if otherPart.Parent:FindFirstChild("Humanoid") and otherPart.Parent ~= self.enemyModel then
damageTarget(otherPart, otherPart.Parent.Humanoid, self.damage)
end
end)