Attempt to compare string <= number

Greetings,

I don’t understand why it gave me this error. I find nothing wrong…

	local player = game.Players.LocalPlayer
	local cash = player:WaitForChild("leaderstats"):WaitForChild("Cash")
	local amount = script.Parent.Parent.Amount.Text
	local amountvalue = script.Parent.Amount.Value
	amountvalue = amount
		if cash.Value >= amountvalue then   ---This is line 16 as said on the error
			if game.Players:FindFirstChild(receiver) then
				print("Amount is: " ..amountvalue)
				print("Final amount is: " ..finalamount)
				print("Receiver is: " ..receiver)
				re:FireServer(amount, receiver, sender, finalamount, cash, amountvalue) 
				print("Remote event for sending has been triggered.")
				script.Parent.Text = "Money has been sent!"
				wait(2)
				script.Parent.Text = "Send (5% tax is applied when sent)"
			elseif not game.Players:FindFirstChild(receiver) then
				print("Receiver " ..receiver.. " not found.")
				script.Parent.Parent.Player.PlaceholderText = "Player not found."
				wait(2)
				script.Parent.Parent.Player.PlaceholderText = "Insert player name here"
			end
		elseif cash.Value < amountvalue then
			script.Parent.Text = "You have insufficient funds."
			wait(2)
			script.Parent.Text = "Send (5% tax is applied when sent)"
		end

Please help, I really don’t know where I am wrong. Thanks!

what’s line 16 exactly? please send the line

I wrote on the script (character limit)

		if cash.Value >= amountvalue then   ---This is line 16 as said on the error

You’re simply just comparing a string with a number, which is pretty much impossible.
cash.Value or amountValue appears to be a string, and both appear to be an NumberValue or StringValue instance.
It’s a simple case of converting the StringValue to a NumberValue.

1 Like

I am not really sure about that. amountvalue is a numbervalue located in the same folder. cash is a numbervalue located in leaderstats folder.

In a next script, where the player gets money or pays money it works just fine.
Btw if you don’t know what I am trying to do, this is a payment system for players. This system works fine if I remove the cash.value <= amountvalue condition.

Amount is a text → string

30charz

Amountvalue is a numbervalue located in the same folder and amount is a textbox.

I just reread the top section, and you’re right. It’s setting the amount to script.Parent.Parent.Amount.Text, which returns a string type.
If the text is ONLY numbers, you can convert it using tonumber()

1 Like

Alright, but is there a way the person can only write number characters in that textbox? (I want to mention I didn’t place the hole script on the site since its very long, making people just say skip). I only placed the part that is important. Because if I remove that line it works just fine. Here is the entire script:

script.Parent.MouseButton1Click:Connect(function(player)
	local player = game.Players.LocalPlayer
	print(player.Name.. " is the sender")
	local sender = player.Name
	local cash = player:WaitForChild("leaderstats"):WaitForChild("Cash")
	local receiver = script.Parent.Parent.Player.Text
	local amount = script.Parent.Parent.Amount.Text
	local amountvalue = script.Parent.Amount.Value
	amountvalue = amount
	local rs = game:GetService("ReplicatedStorage")
	local re = rs:WaitForChild("Sending"):WaitForChild("Send")
	local percent = amountvalue / 20
	local finalamount = amount - percent
	
	if script.Parent.Parent.Player.Text ~= "" and script.Parent.Parent.Amount.Text ~= "" then
		if cash.Value >= amountvalue then
			if game.Players:FindFirstChild(receiver) then
				print("Amount is: " ..amountvalue)
				print("Final amount is: " ..finalamount)
				print("Receiver is: " ..receiver)
				re:FireServer(amount, receiver, sender, finalamount, cash, amountvalue) 
				print("Remote event for sending has been triggered.")
				script.Parent.Text = "Money has been sent!"
				wait(2)
				script.Parent.Text = "Send (5% tax is applied when sent)"
			elseif not game.Players:FindFirstChild(receiver) then
				print("Receiver " ..receiver.. " not found.")
				script.Parent.Parent.Player.PlaceholderText = "Player not found."
				wait(2)
				script.Parent.Parent.Player.PlaceholderText = "Insert player name here"
			end
		elseif cash.Value < amountvalue then
			script.Parent.Text = "You have insufficient funds."
			wait(2)
			script.Parent.Text = "Send (5% tax is applied when sent)"
		end
	elseif script.Parent.Parent.Player.Text == "" then
		script.Parent.Parent.Player.PlaceholderText = "Please fill this line"
		wait(2)
		script.Parent.Parent.Player.PlaceholderText = "Insert player name here"
	elseif script.Parent.Parent.Amount.Text == "" then
		script.Parent.Parent.Amount.PlaceholderText = "Please fill this line"
		wait(2)
		script.Parent.Parent.Amount.PlaceholderText = "Insert amount here"
	end
end)

You could use string.gsub() to remove any non number character, not sure to how remove any letter in just one line

Where do I have to place that? I am a beginner and I can currently work only with some basic functions.

It works like this
string.gsub(anytext, textYouWantToReplace, Replace)

Example

Text = “Hello!”
string.gsub(Text, “ello”, “i”)

Output: Hi!

1 Like

Ok thanks, I will look into that.

1 Like

Oh yeah, just real quick, use task.wait(), it’s new but it’s an improved version of wait().

Anyways, you want to just place it after or where you assign amount.
However, I would suggest assigning it to the text itself after the user is done typing, as otherwise they may accidentally send 2345 instead of 23.45, but I can’t think of a case where they’d pay with a float, so you could also round it.

1 Like

Alright, thanks, but how can I solve that error though?

Think you have to do amount.Value = amount.Text or something. That’s why it’s errorring

	local amount = script.Parent.Parent.Amount.Text
	local amountvalue = script.Parent.Amount.Value
	amountvalue = amount

Whoops, my bad lol. Ignore my mistake.

No problem, please check for my full script located in one of my comments.

The amount text exactly is always a number or can have letters in it?