Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago
Edited 6 years ago

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
    })

0
which line? is it in the CreateRaycast function User#5423 17 — 6y

1 answer

Log in to vote
1
Answered by
theCJarmy7 1293 Moderation Voter
6 years ago

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.

0
Order of operations apply to .magnitude too. Professor_Boxtrot 136 — 6y
Ad

Answer this question