Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

May I have help figuring out this banking GUI script?

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

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.

3 comments

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

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.

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.

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! :)

This discussion is preserved as it was. New answers, comments, and votes are closed.