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

How do I make a GUI button give me + 1 money every time it is clicked?

Asked by
xf8d 5
5 years ago

I have been trying to write a script where if I click a GUI button it gives you + 1 money and it doesn't work. It says it has to be an equal sign. So can someone please tell me how to get it to be a plus sign. button.MouseButton1Click:Connect(function()

player.Character.leaderstats.OoferBucks.Value = 1

end) That is what I have right there if I put a + sign where the equal sign is it says that it is wrong. If someone could tell me what to do that would be awesome. Thanks!

2 answers

Log in to vote
0
Answered by 5 years ago

Your current line player.Character.leaderstats.OoferBucks.Value = 1 The problem with this, is that it will constantly set the value to 1, instead of adding.

First of all, I'll add a line that holds the OoferBucks Instance, to make the next line shorter and easier to understand:

local OoferBucks = player.Character.leaderstats.OoferBucks

Next, the correct way to add 1 to a value, is to set its value to itself + 1. Like this:

OoferBucks.Value = OoferBucks.Value + 1

So the final script would be:

local OoferBucks = player.Character.leaderstats.OoferBucks
OoferBucks.Value = OoferBucks.Value + 1

Hope this helps!

0
It says that leaderstats is not a valid member of Model xf8d 5 — 5y
0
Well, it turns out you never created the leaderstats folder. See the answer below. LisaF854 93 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

You would start of by making leaderstats

-- Normal script in ServerScriptService
game.Players.PlayerAdded:Connect(function(Player)

local Stats = Instance.new("Folder", Player)
Stats.Name = "leaderstats" -- The name most be leaderstats, or this would not work!

local Money = Instance.new("IntValue", Stats)
Money.Name = "Money"
Money.Value = 0

end)

So now, you would need another script inside the gui button, remember it should be a Local Script.

local Player = game.Players.LocalPlayer
local Stats = Player:WaitForChild("leaderstats")
local Money = Stats:WaitForChild("Money")

local UI = script.Parent -- UI is the ScreenGui
local Button = UI.Button

local Debounce = false -- this prevent from spamming the button!
Button.MouseButton1Click:Connect(function()
  if Debounce == false then
      Debounce = true

      Money.Value = Money.Value + 1

      wait(2) -- this is the amount of secounds you should wait before getting more money!

      Debounce = false
  end  
end)

Hope this helped you out, this is not FE Enabled!

0
Then make it FE enabled. Just fire a remote event lmao BlackOrange3343 2676 — 5y
0
Nice try being smart when you're actually not. You can no longer toggle FE. DeceptiveCaster 3761 — 5y
0
It says that button is not a valid memeber of text button xf8d 5 — 5y
0
@MCAndRobloxUnited, you can lol, go check that TheDev321 37 — 5y
View all comments (2 more)
0
Im not gonna just give that dude the answerer, let him work on it, I just gave him the basics TheDev321 37 — 5y
0
it works fine diego_daboss1134 0 — 4y

Answer this question