Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why do i get attempt to compare number with string error?

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

2 comments

0

Make sure the Cash.Value is a numbervalue and not a stringvalue.

0

Huh? What do u mean by that?

1 answer

✓ Accepted answer

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)

3 comments

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?

0

It was probably because you were using something other then a number value so instead I did a conversion between string to number

0

Can u check my latest question because it's almost the same but instead of string its nil

This discussion is preserved as it was. New answers, comments, and votes are closed.