Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can someone help me with this script?

Asked by 9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

So, I'm trying to do a banking system. I have the money and the bank GUI working, but this does not seem to work. Can someone help me figure out why it when I insert the value I want to deposit it won't change the text of the Bank Money GUI.

function hi()
    local player = game.Players.LocalPlayer
    bank = player.BankSave.Value
    money = player.MoneySave.Value
    withdraw = script.Parent.Parent.MoneyValue
    withdrawcash = script.Parent.Parent.MoneyValue.Value
    if money >= withdrawcash then
        bank = withdraw.Value+bank
        print("we just deposited some moolah")
        script.Parent.Parent.Visible = false
        script.Parent.Parent.Parent.Good.Visible = true
    else
        script.Parent.Parent.Visible = false
        script.Parent.Parent.Parent.Error.Visible = true
    end

end


script.Parent.MouseButton1Down:connect(hi)

1 answer

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

Your assignments to bank and money set bank and money to numbers. Because the Value property is just a number.

It does not link the variable bank and the Value of the BankSave value.


Your variable names should be clearer. What you are doing is a deposit, not a withdrawal.

I am not understanding the purpose of your four Value objects, but here is a simplification involving three of different possible names to illustrate how this will work:

function hi()
    local player = game.Players.LocalPlayer

    bank = player.BankSave
    cash = player.MoneySave
    deposit = player.Deposit

    if cash.Value >= deposit.Value then
        bank.Value = bank.Value + deposit.Value
        cash.Value = cash.Value - deposit.Value

        print("we just deposited some moolah")
        script.Parent.Parent.Visible = false
        script.Parent.Parent.Parent.Good.Visible = true
    else
        script.Parent.Parent.Visible = false
        script.Parent.Parent.Parent.Error.Visible = true
    end
end

script.Parent.MouseButton1Down:connect(hi)
Ad

Answer this question