So I am trying to make a bank ATM. I made the gui so it is like I have a textbox then 2 buttons. 1 Button says 'Deposit' and the other one says 'Withdraw'. So when I enter a amount and then click on any of those buttons this error shows up:
07:45:56.117 - Players.iiLevelMaker.PlayerGui.ATMGui.Container.withdraw.LocalScript:9: attempt to compare string with number
This is the script for deposit:
local player = game:GetService('Players').LocalPlayer local gui = player:WaitForChild('PlayerGui'):WaitForChild('ATMGui') local button = gui:WaitForChild('Container').deposit local amountbox = gui:WaitForChild('Container').TextBox local cash = player.leaderstats.Cash local bank = player.leaderstats.Bank function MouseClick() if cash.Value >= amountbox.Text then bank.Value = bank.Value +amountbox.Text cash.Value = cash.Value -amountbox.Text end end button.MouseButton1Click:connect(MouseClick)
This is the script for withdraw:
local player = game:GetService('Players').LocalPlayer local gui = player:WaitForChild('PlayerGui'):WaitForChild('ATMGui') local button = gui:WaitForChild('Container').withdraw local amountbox = gui:WaitForChild('Container').TextBox local cash = player.leaderstats.Cash local bank = player.leaderstats.Bank function MouseClick() if bank.Value >= amountbox.Text then cash.Value = cash.Value +amountbox.Text bank.Value = bank.Value -amountbox.Text end end button.MouseButton1Click:connect(MouseClick)
You need to use the tonumber
function so that you can compare the string :)
local player = game.Players.LocalPlayer local gui = player:WaitForChild('PlayerGui'):WaitForChild('ATMGui') local button = gui:WaitForChild('Container').withdraw local amountbox = gui:WaitForChild('Container').TextBox local cash = player.leaderstats.Cash local bank = player.leaderstats.Bank function MouseClick() --Convert string to a number datatype local amount = tonumber(amountbox.Text) if bank.Value >= amount then cash.Value = cash.Value +amount bank.Value = bank.Value -amount end end button.MouseButton1Click:Connect(MouseClick) --'connect' is deprecated