Projectile error (attempt to perform arithmetic (unm) on nil)

Hello Developers :wave:,
I am having trouble finding out how to fix this error.

  • Attack function (One with the error)
function Attack(torso, Distance)
	if CoolDown <=0 or Refresh == true then
		local laser = Instance.new("Part", workspace.Projectiles)
		laser.Name = "Laser"
		
		laser.Anchored = true
		laser.CanCollide = false
		laser.CastShadow = false
		
		laser.Shape = "Cylinder"
		laser.Color = Color3.fromRGB(255, 0, 0)
		laser.Material = Enum.Material.Neon
		
		laser.CFrame = CFrame.new(script.Parent.Position, torso.Position) * CFrame.new(0, 0, - Distance/2)
		laser.Size = Vector3.new(4, GetDistance(torso, Distance), 4)
		
		laser.Transparency = 0.5
	end
end
  • Function that is apart of the error
local function GetDistance(torso, Distance)
	Distance = (script.Parent.Position - torso.Position).magnitude
	return Distance
end

Feel to make any edits to this script!

EDIT: the line 52 and, 76 are all linked to line 43 (Attack Function) don’t worry about it unless you positive its something to do with that!

It’s telling you that you are trying to unm(-) a nil value, so in the attack function Distance is nil, so you aren’t passing the correct value in(because GetDistance looks fine)

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.