✓ Accepted answer
You could have a GUI that pops up when the ATM is clicked, and with a button that lets you withdraw money, with a TextBox to put an amount. I will remake the code, as well as the Gui coding part. I also added another RemoteEvent that fires to the client if they try to get more money than what they have.
local withdraw = game:GetService("ReplicatedStorage").Money.ATM.Withdraw
withdraw.OnServerEvent:Connect(function(plr, amount)
if plr.stats.Bank.Value >= amount and plr.stats.Bank.Value > 0 then
plr.stats.Money.Value = plr.stats.Money.Value + amount
else
withdraw.Parent.WithdrawError:FireClient(plr, "Not enough money!")
end
end)
The LocalScript with the TextBox to insert amount.
local withdraw = game:GetService("ReplicatedStorage").Money.ATM.Withdraw
local function makeTextNumber()
tonumber(script.Parent.Parent.MoneyAmount.Text)
end
pcall(makeTextNumber)
script.Parent.MouseButton1Click:Connect(function()
withdraw:FireServer(
tonumber(script.Parent.Parent.MoneyAmount.Text)
)
makeTextNumber()
end)
Now for the WithdrawError RemoteEvent I made in the Server script.
local withdrawError = game:GetService("ReplicatedStorage").Money.ATM.WithdrawError
withdrawError.OnClientEvent:Connect(function(msg)
script.Parent.Text = msg
wait(2)
script.Parent.Text = "Withdraw"
end)
1 comment
Thank you I did't know what Avigant mean't but now I know since I saw the script. I guess next time for future people who need help just use the tonumber in the way your firing the event