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

May I have help figuring out this banking GUI script?

Asked by 8 years ago

I've been tinkering with the one below for a few hours now and I haven't been able to get it to work. All I want it to do is subtract 50 from one value (as long as they have at least 50) and then add 50 to another value. I'm stumped!

local Button = script.Parent
local Money = game.Player.Wealth.Money
local Bank = game.Player.Wealth.Bank
function deposit50()
    if tonumber(Money.Text) > 50 then
        Money.Text = tostring(tonumber(Money.Text) - 50)
        Bank.Text = tostring(tonumber(Bank.Text) + 50)
    else
end
    end

Button.ClickDetector.MouseClick:connect(deposit50)

Thank you for your help!

2 answers

Log in to vote
1
Answered by
Cuvette 246 Moderation Voter
8 years ago
Edited 8 years ago

First of all, I'm guessing you're trying to access the Gui. You'd need to do so by searching in game.Players.LocalPlayer.PlayerGui. game.Player doesn't access anything and to use LocalPlayer you would need to be using a LocalScript, other you can find the player by using script.Parent.Parent.Parent etc...

Lets assume you're using a LocalScript for this part, ill give you a quick edit below.

Player = game.Players.LocalPlayer
Button = script.Parent
Money = Player.PlayerGui.ScreenGui.Wealth.Money
Bank = Player.PlayerGui.ScreenGui.Wealth.Bank

Button.ClickDetector.MouseClick:connect(function()
    if tonumber(Money.Text) > 50 then
        Money.Text = tostring(tonumber(Money.Text) - 50)
        Bank.Text = tostring(tonumber(Bank.Text) + 50)
    end
end)

You would be better off having Int values or even storing the values to a leaderboard. As this way isn't very efficient if you're going to be using it in an actual game, due to being easily exploitable client side.

Also I've condensed the function down to just the mouse click. There's no need to have it switch functions if you're only having the button do one thing on click.

1
Thank you for replying! My stats I guess technically are on a leaderboard script however I renamed leaderstats to wealth. Is this script drawing the values from that location? It doesn't seem to work. Thank you again for taking time to help me. https://gyazo.com/38d8797913799126d4904ece623534ed marsupicide 60 — 8y
0
I'm sorry if I'm asking a question you already answered, but I'm afraid I don't speak the language haha. I'm trying to get this thing to subtract 50 from the Money Value and add 50 to the Bank value located in Wealth. marsupicide 60 — 8y
0
You're going to have to re-define variables. The button won't be script.Parent if you're using a Local Script, which you should be. Instead, you're going to have to look in workspace. OldPalHappy 1477 — 8y
Ad
Log in to vote
1
Answered by 8 years ago

Never mind guys! I looked up a tutorial on functions and I figured it out myself. Here is the finished deposit script if anyone wants to see.

local player = game.Players.LocalPlayer
local money = player:WaitForChild('Wealth').Money
local bank = player:WaitForChild('Wealth').Bank

script.Parent.MouseButton1Down:connect (function()
if player.Wealth.Money.Value >= 50 then
player.Wealth.Money.Value = player.Wealth.Money.Value - 50
player.Wealth.Bank.Value = player.Wealth.Bank.Value + 50
else print ('yo homie you broke') 
end
end)

Pretty simple script, but it's my first one so I'm pretty proud. Thanks for being an inspiration SH! :)

Answer this question