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

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

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

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!

2 comments

0

It says that leaderstats is not a valid member of Model

0

Well, it turns out you never created the leaderstats folder. See the answer below.

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!

6 comments

0

Then make it FE enabled. Just fire a remote event lmao

0

Nice try being smart when you're actually not. You can no longer toggle FE.

0

It says that button is not a valid memeber of text button

0

@MCAndRobloxUnited, you can lol, go check that

0

Im not gonna just give that dude the answerer, let him work on it, I just gave him the basics

0

it works fine

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