"attempt to compare string <= number"

So I am making a banking system and have been trying hard to fix problems with the Withdraw function but keep getting errors that I fixed but can’t fix this one please help me!

game.ReplicatedStorage.BankingEvents.CheckWithdraw.OnServerEvent:Connect(function(player)
	local Amount = tonumber(player.PlayerGui.ATMSystem.Checkings.Amount.Text)

	if player.data.Checkings.Value <= 0 then return end
	if player.data.Checkings.Value > 0 and player.data.Checkings.Value >= Amount then
		player.data.Checkings.Value = player.data.Checkings.Value - Amount
	end
end)

Error:

1 Like

Is the text only numbers and nothing else?

Also, your error is trying to say that you’re trying to compare nothing to a number.

2 Likes

Ye I am pretty sure. Also wait a minute? What?

1 Like

player.data.Checkings.Value is nil. It says attempt to compare nil <= number, not string.

2 Likes

I said, your error is saying your error trying to compare nothing to a number.

2 Likes

@ItzMeZeus_IGotHacked is right since if there is text in the called string, I learned that the outcome will be nil. Check your local script to see if the input has non-numbers text in it.

3 Likes

Oh my goodness I am so dumb! I forgot to bring the Amount text from the the localscript over to the server script so now it thinks there is no text! I need to edit the remote event and I will see if it fixes that.

You can show us the part where you fire the remote event from the local script for us to help you.

script.Parent.MouseButton1Click:Connect(function(player)
	local player = game.Players.LocalPlayer
	
	game.ReplicatedStorage.BankingEvents.CheckWithdraw:FireServer(player)
end)
1 Like

Yeah nothing important, I guess the problem is your backend.

2 Likes

Wait what? Blackened impossible my scripts are from me!

Also FireServer() works without giving the player param, but you need it in the server script.

2 Likes

No no I mean, backend means the main thing that controls behind the scenes. Malicious backend scripts are backend that serves the purpose of hacking.

1 Like

Ah, well I will try to fix this thing and see if it worked.

1 Like

Hey!

You can easily add String Patterns as a better check for numbers. As a example, for digits you would need %d. To get multiple digits and not just the first one of the string, add a + to your pattern.

Now, after this is done, easily check the string with string.match, for example

if string.match("Your Text!", "%d+") then
    -- Your code
end

I hope this helps you out with your problem!

Cheers

3 Likes

Nonono No need for that it is already in one of my scripts.I just need to edit the remote event but thank you!

Okay but now I need help transferring the text from the client to the server.

1 Like

Hey!

You can easily add as many arguments to your RemoteEvent | Roblox Creator Documentation function. Just add your values in between the brackets of the client side, for example

RemoteEvent:FireServer("Your Text!")

After that is done, you need to reference the same exact RemoteEvent | Roblox Creator Documentation in the server.
If thats done, add a RemoteEvent | Roblox Creator Documentation event in the server. Important to know here is, the first argument passed is the player, after that are your own arguments.

This looks like this example:

RemoteEvent.OnServerEvent:Connect(function(player, YourArgument) 
    -- Code here
end)

There you have your text as YourArgument passed and ready to use in the server.

Hope this could help you!

Cheers

Thank you after 2 days of fixing this this helped me a lot!

1 Like

Hey!

Absolutely no problem, have fun developing!

Cheers

1 Like