ReplicatedStorage.Spring:208: attempt to compare number < nil

Hello,
I Got This Error
ReplicatedStorage.Spring:208: attempt to compare number < nil
With a spring module that im using
Heres my code

	local updatedrecoilspring = recoilSpring:update(dt)
	camera.CFrame *= CFrame.Angles(math.rad(updatedrecoilspring.x),0,0)
end)

Weapon.Equipped:Connect(function(mouse)
	IdleAnim:Play()
	
	mouse.Button1Down:Connect(function()
		if Weapon.Ammo.Value > 0 then
			WeaponShootSFX:Play()
			ShootAnim:Play()
			Weapon.Ammo.Value = Weapon.Ammo.Value - 1
			recoilSpring:shove(Vector3.new(4,0,10))
		else
			print("Ammo Empty")
		end
	end)
1 Like

I’m assuming that line 208 is

if Weapon.Ammo.Value > 0 then

In that case, read the error carefully. It’s telling you that you are trying to compare a number with a nil value. You can’t do that because its unclear what the outcome is. Here, 0 is the number value. Therefore, we know that Weapon.Ammo.Value is nil.
If this is a big problem for you, simply add

if Weapon.Ammo.Value then -- check if the value is not nil
    if weapon.Ammo.Value > 0 then
--        bla bla bla
    end
end

Hope this helped!

thanks for trying to help me but

Can I see your actual code? Make sure you added the

if Weapon.Ammo.Value then

line.

Remember if Value is nil it could also be that Ammo is nil, so I would recommend to add these prints before mentioning them:

print(Weapon)
print(Ammo)
print(Ammo.Value)

If I am correct you will get: something, nil, nil.

I get

  12:48:58.570  M4A1  -  Client - LocalScript:105
  12:48:58.571  Ammo  -  Client - LocalScript:106
  12:48:58.573  29  -  Client - LocalScript:107 

Its the spring module that has something wrong with it if im correct.

print the Weapon’s Value immediately before doing the if check

its fine i fixed it, the module was outdated had to use a new version thanks for trying to help me tho i appreciate it!