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!
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.
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.
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()
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)
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.