Money being multiplied by 2 every click?

I want to make a system where the money you get per click is added by one every time the item is bought however if you buy it once than it adds it like normal but then suddenly makes it like 4 and multiplying by 2 every click? how can I prevent this from happening?
Here’s the script.

local amount = 1
	game.Players.LocalPlayer.leaderstats.Money.Value = game.Players.LocalPlayer.leaderstats.Money.Value + amount
	if game.Players.LocalPlayer.Backpack:FindFirstChild("Grey Cube") then
		amount = amount + 1

I have already tried brainstorming solutions but to no avail.

First of all, what is the wait(.1) for?
Secondly, this script can be exploited very easily since an exploiter can edit the amount to a huge number to instantly get alot of money. However, the money won’t even update on the server currently, since you are setting it using a local script.
I am not sure what you are asking, but I can tell you a small tip to make your scripts less cluttered:

Instead of:

amount = amount + 1

You can use:

amount += 1

Same with

game.Players.LocalPlayer.leaderstats.Money.Value = game.Players.LocalPlayer.leaderstats.Money.Value + amount

Which can be changed to:

game.Players.LocalPlayer.leaderstats.Money.Value += amount

So im still new but I think the .1 helps prevent auto clickers and for the second one its just a test so im not so worried about exploiters
What im trying to do is when you click a button it gives a one dollar and when you buy the grey cube thing it adds by one and only one but what its doing is adding more than once per click

the reason why this is happening is that you keep adding to the amount so basically you are adding to the amount and then adding to the player stat value.
you should do

game.Players.LocalPlayer.leaderstats.Money.Value = amount

then put it under the if statment
Even though your problem is solved now, you shouldn’t do this, as people can just give them self free money

Instead of simply doing wait(.1), you would have to add a debounce since right now the script would just run 0.1 second late, not actually slowing it.
To make a debounce:

local debounce = false
        if debounce == false then
              debounce = true
              -- your script here

                 -- in the end after script ends,
                wait(0.1) -- you can also use task.wait(0.1), which should be more accurate
                 debounce = false

Basically, what a debounce does is prevents something from running.
For now, try to apply what I told you, and see if it still does this, since it could have been a problem with the click cooldown

Edit: Do you want the amount of money to always increase or not?
Click 1: +1 Money
Click 2: +2 Money
Click 3: +3 Money
Click 4: +4 Money


you should learn about RemoteEvents to help your game be less exploitable,

What should be happening is when you dont buy the item you only gain one dollar per click however once you buy the item you get 2 dollars per click

And ill be sure to check that out

If I understood correctly, I think your issue is that you keep increasing Amount every time they click.
The solution for now could be replacing:

amount = amount + 1


amount = 2

Since that will prevent it from increasing every time you click. However, this is probably not the most ideal method to do this.

That does work but for future refrence how can I make it so with every time the cube is purchased it goes up by 1

How does the cube purchase work exactly? Maybe you could count the amount of cubes in the inventory and increase by that amount.
Also, I recommend doing all this on the server, including the amount.
All you would need from the client is sending the event that the player clicked, and calculate everything on the server

The cube purchase thing is simple if you have over 100 dollars you can buy the cube and it appears in your hotbar but if you don’t you cant buy it

The cube is a tool right?
Basically what you could do is first count the amount of cubes in the player backpack:

Note: You might have to edit this a bit since I didn’t write this in studio

local CubesFound = 0 -- used later
for i,Item in Player.Backpack:GetChildren() do  -- loops through every item in backpack
       if Item:IsA("Tool") and Item.Name == "Grey Cube" then -- if tool and name is "Grey Cube" then
                CubesFound += 1  -- increase amount by 1
Money.Value += CubesFound

You can use something like this.
Also, in this case Attributes might be useful, for example for having different amount of cash increase for different cube types.

Ohhh ill be sure to try that soon

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.