Hello, I’m trying to make my users be able to deposit their in-game currency into their in-game bank vault. In my game I have three currencies: Galleons, Sickles and Knuts so I made a GUI that lets them choose the currency they want to deposit.
When they press enter after writing the amount of that currency they want to deposit, it should add to their vault that amount and decrease the current user’s amount, for that I use this code:
local TS = game:GetService("TweenService")
local RS = game:GetService("ReplicatedStorage")
local GringottsDir = RS.Gringotts
local RemoteEvents = GringottsDir.RemoteEvents
local DepositTransactionRE = RemoteEvents.DepositTransaction
DepositTransactionRE.OnServerEvent:Connect(function(Player, value, currencyType)
if Player.leaderstats[currencyType].Value >= value then
-- TODO: Transaction
Player.leaderstats.Stored[currencyType].Value += value
Player.leaderstats[currencyType].Value -= value
return
end
end)
This is a server script.
I also have a localscript:
script.Parent.Second.DepositButton.MouseButton1Click:Connect(function()
local Children = script.Parent.Second:GetChildren()
for i = 1, #Children do
if Children[i].Name ~= "DepositTextBox" or "DepositCloseButton" then
Children[i].Visible = false
end
end
script.Parent.Second.DepositTextBox.Visible = true
script.Parent.Second.DepositCloseButton.Visible = true
script.Parent.Second.DepositTextBox.FocusLost:Connect(function(key)
local text = script.Parent.Second.DepositTextBox.Text
print("HELLO TEXT ISNT NIL")
if key then
print("HELLO KEY ISNT NIL")
if tonumber(text) then
print("tonumber")
local value = tonumber(text)
local currencyType
print("before for :(")
for i = 1, #currencies do
print("?")
if script.Parent.Second.DepositTextBox.DepositTextBox.Text == "" then
print("a")
end
if script.Parent.Second.DepositTextBox.DepositTextBox.Text == currencies[i].Name then
print("transaction")
-- TODO: Transaction
currencyType = script.Parent.Second.DepositTextBox.DepositTextBox.Text
DepositTransactionRE:FireServer(value, currencyType)
print("after transaction")
end
end
end
end
end)
end)
But none of the prints work, and I get no errors from the console nor the transaction gets completed.
I have already tried remaking the GUI, changing how the script works (before it was in StarterPlayer, now it is in a folder in StarterGui) and using prints to try to check where was the issue. Nothing worked.
(Btw, before adding the currency types selection, the transaction worked correctly, so it isn’t a problem that had the original code).
This is how the GUI looks:
Explorer View: