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 string error?

Asked by 6 years ago
Edited 6 years ago

So i made a Coffee Shop and did all i could. I made also this script and it always shows me this error... Here is my script :

Coffee = 2

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

        end
      end   
    end)

The error says its on line 6. So this one : if player.leaderstats.Cash.Value >= Coffee then .. Help me please

0
Make sure the Cash.Value is a numbervalue and not a stringvalue. ultrasonicboomer 85 — 6y
0
Huh? What do u mean by that? Zippermen 2 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Try this

Coffee = 2

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) >= Coffee then
            player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - Coffee  
            script.Parent.Parent.sadle.BrickColor = BrickColor.Random()
            local copy = game.ServerStorage.Coffee:Clone()
            copy.Parent = game.Players.LocalPlayer.Backpack

        end
      end   
    end)
0
Dude thank you so much. But i don't understand why i had to give this next to it because there was a youtube scripter that did the same thing and it worked for him and the video was in December 2017. Actually can i contact u where if i need anymore help? Zippermen 2 — 6y
0
It was probably because you were using something other then a number value so instead I did a conversion between string to number SilentGalaxZy 53 — 6y
0
Can u check my latest question because it's almost the same but instead of string its nil Zippermen 2 — 6y
Ad

Answer this question