Now the bullet should go forward yet for some reason it doesn't? My code:

local gun = script.Parent

function findTarget()

local dist = 200

local target = nil

for i,v in pairs(workspace:GetChildren()) do

local torso = v:FindFirstChild("Torso")

local human = v:FindFirstChild("Humanoid")

if v.Name == "Soldier" and torso and human then

if (gun.Position - torso.Position).magnitude < dist and human.Health > 0 then

dist = (gun.Position - torso.Position).magnitude

target = torso

end

end

end

return target

end

  

while wait(1) do

local torso = findTarget()

if torso then

gun.CFrame = CFrame.new(gun.Position, torso.Position)

local b = Instance.new("Part",workspace)

b.Size = Vector3.new(0.2,0.2,1)

b.BrickColor = BrickColor.new("Really black")

b.CFrame = gun.CFrame + Vector3.new(0,0,-2)

b.Velocity = gun.Cframe.lookVector * 200

b.Touched:Connect(function(obj)

local humanoid = obj.Parent:FindFirstChild("Humanoid")

if humanoid then

humanoid:TakeDamage(25)

end

if onj ~= gun then

game:GetService("Debris"):AddItem(b,0)

end

end)

end

end

Not sure why this is happening but i'm hoping somebody can help

3 comments

0

maybe its the gun's orientation? Check the front surface on it.

0

I put the code in a code block.

0

Sorry that it wasn't in a code block the interface changed with text editing n such. And the orientation is correct the bullet just drops on the ground for no reason