Simulator script won't work

Hello. I am a scripter on my main, and I am making a button simulator where you click a button to add cash instead of adding cash every second, but my script is not working. I want it so that if you have 0 rebirths, you get 1 cash, 1 rebirth times 2 cash, 2 rebirths times 3 and so on. This is my script i have so far.

The issue is that it will not multiply 1 by the +1 of the amount of multiplier they have.

local player = game.Players.LocalPlayer
local multiValue = player.leaderstats.Multi.Value

script.Parent.MouseButton1Click:Connect(function()
	if multiValue <= 0 then
		player.leaderstats.Cash.Value = player.leaderstats.Cash.Value +1
		script.Parent.Parent.Visible = false
		wait(.5)
		script.Parent.Parent.Visible = true
	else
		player.leaderstats.Cash.Value = player.leaderstats.Cash.Value +(2*multiValue)
		script.Parent.Parent.Visible = false
		wait(.5)
		script.Parent.Parent.Visible = true
	end
end)

Any feedback helps. Thanks!

1 Like

Your supposed to put a space between adding a value. Example + 1 instead of +1

1 Like

It adds cash to the player already, but it won’t do the second part. Anything after else won’t work.

1 Like

What is the .5 for? 30charsssss

1 Like

It is a delay system to prevent autoclickers from ruining the game. It simply just disables the button for half a second.

1 Like

You gonna have to ask some other people about this. I would suggest asking this question to Kamlkaze_kid

1 Like

Thank you for the suggestion! 30charsssssssssss

LUA is not too picky about white space, so this would work the same with or without a space

1 Like

The whole thing about this is that it is adding cash on the client side, and not the server side. You will need to implement a remote event

1 Like

I am not good with events, care to explain to me what to do?

1 Like

I would like to point out some things that needs to fixed:

  1. Changing a value in the client won’t replicate to the server, you would have to utilize remote events.
  2. It doesn’t matter if there is a space or not. As @DarkDanny04 said, LUA is not too picky.

Seems like @DarkDanny04 had already said my word :flushed:

1 Like

What remote would I have to use and how would I have to use it?

1 Like

You can either use RemoteEvents or RemoteFunctions. You can learn about it here: Custom Events and Callbacks | Documentation - Roblox Creator Hub

Thank you! 30charssssssssssssssssssssssssssssssssssssss

1 Like

What is multiValue? Are you expecting it to change while the game is running, and what is the Value of it when the game starts?

The value of it when the game starts is 0, which you gain by stepping on a button when you reach enough cash to buy it.

You should replace

local multiValue = player.leaderstats.Multi.Value

with

local multiValue = player.leaderstats.Multi

As what you are effectively doing is saying

local multiValue = 0

And if you update multiValue.Value, it won’t update the variable with the new changes you made to it.

You should also replace all the times you use multiValue with multiValue.

local player = game.Players.LocalPlayer
local multiValue = player.leaderstats.Multi -- Made changes

script.Parent.MouseButton1Click:Connect(function()
	if multiValue.Value <= 0 then
		-- Communicate to server via remote event to increase money
		script.Parent.Parent.Visible = false
		wait(.5)
		script.Parent.Parent.Visible = true
	else
		-- Communicate to server via remote event to increase money, multiplied by multiValue
		script.Parent.Parent.Visible = false
		wait(.5)
		script.Parent.Parent.Visible = true
	end
end)

I’ve commented where I changed the script.

2 Likes

Thank you! 30charsssssssssssss

Does this need to be in a script or a localscript?

1 Like

I’ve just made changes to the script.

This script should be in a LocalScript, but you should also make a RemoteEvent, and a Script, as mentioned before, changes you make on your client dont replicate to the server and other clients in this case. The server should handle adding the cash to the servers end.