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

How to compare a String with a Number? [closed]

Asked by 9 years ago
donateButton.MouseButton1Down:connect(function(donate)
    if game.Players:FindFirstChild(playerName.Text) then
        local donatePlayer = playerName.Text
        print("PLAYER FOUND")
        if player.leaderstats.Cash.Value >= donateAmount.Text then -- ERROR HERE
            print("GOOD AMOUNT")
            player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - donateAmount.Text
            donatePlayer.leaderstats.Cash.Value = donatePlayer.leaderstats.Cash.Value + donateAmount
        end
    end
end)

PLAYER FOUND 10:55:29.674 - Players.Player.PlayerGui.HUD.DonateFrame.DonateScript:29: attempt to compare string with number 10:55:29.675 - Stack Begin 10:55:29.676 - Script 'Players.Player.PlayerGui.HUD.DonateFrame.DonateScript', Line 29 10:55:29.677 - Stack End Everything has been defined so don't worru about that. How can I get the string to compare with a number?

Locked by NinjoOnline, Goulstem, and Muoshuu

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

1 answer

Log in to vote
2
Answered by
parkderp1 105
9 years ago

Use tonumber()

if player.leaderstats.Cash.Value >= tonumber(donateAmount.Text) then

0
Warning: `tonumber` will return `nil` if you didn't get it text that precisely represents a number! BlueTaslem 18071 — 9y
Ad