Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

bad argument #2 to '?' (Vector3 expected, got number) 21:24:16.280 - Stack Begin

Error I get bad argument #2 to '?' (Vector3 expected, got number) 21:24:16.280 - Stack Begin

Error happens on line 4

function FireLaser(mouse, count)
  local aimPos = mouse.hit.p
  local bulletOrigin = BulletOrigin.Position
  local distance = bulletOrigin - aimPos.magnitude
  if Recoil < MaxRecoil then
    Recoil = Recoil + 5
  end
  for i = 1, count do
    local aimWithSpread = Vector3.new(aimPos.x + math.random(-(BulletSpread / 10) * distance, BulletSpread / 10 * distance), aimPos.y + math.random(-(BulletSpread / 10) * distance, BulletSpread / 10 * distance), aimPos.z + math.random(-(BulletSpread / 10) * distance, BulletSpread / 10 * distance))
    local collision, collisionPos = CreateRaycast(player.Character.Head.Position, aimWithSpread, {
      player.Character,
      Camera,
      workspace.BulletDump,
      game.ReplicatedStorage
    })

1 comment

0

which line? is it in the CreateRaycast function

1 answer

You cannot add or subtract a Vector3 by a scalar, I assume what you meant to do is:

local distance = (bulletOrigin - aimPos).magnitude
--Parentheses are very important!

Which would indeed return the distance between the two vectors.

1 comment

0

Order of operations apply to .magnitude too.

This discussion is preserved as it was. New answers, comments, and votes are closed.