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

Why do i get attempt to compare number with nil?

Asked by 6 years ago

So the only reason why im posting this is because if i put the price to 2 it's gonna work but if i put it to like 2000 it's gonna send this error. Here is the script :

RKatana = 2000

script.Parent.ClickDetector.MouseClick:Connect(function(player)
    if player:FindFirstChild("leaderstats") then
        -- We know that the player has leaderstats
        if tonumber(player.leaderstats.Cash.Value) >= RKatana then
            player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - RKatana  
            local copy = game.ServerStorage.RKatana:Clone()
            copy.Parent = game.Players.LocalPlayer.Backpack

        end
      end   
    end)

0
Huh.. is the value from the Cash a number or string? TheePBHST 154 — 6y
0
But, if the Cash's Value is a number, then you don't "tonumber". Because, if its a number then you cant get a number out of a number. So, thats why it's nil TheePBHST 154 — 6y
0
Yea but the problem is that if i don't do the tonumber its gonna say attempt to compare number with string thats why Zippermen 2 — 6y

Answer this question