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