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

How to compare a String with a Number?

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?

1 answer

✓ Accepted answer

Use tonumber()

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

1 comment

0

Warning: tonumber will return nil if you didn't get it text that precisely represents a number!

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