opplo
|
  |
| Joined: 09 Dec 2008 |
| Total Posts: 5320 |
|
|
| 06 Jan 2015 06:37 PM |
How do I keep the rand value local to that specific execution of the function. For example if I clicked once and clicked again, after the 5 seconds it would return "rand" as the value from when I clicked the second time.
Hopefully that makes sense, example of output below.
function click() rand = math.random(100,200) print(rand) wait(5) print(rand) end
mouse = game.Players.LocalPlayer:GetMouse() mouse.Button1Down:connect(click)
Output: 123 -- First Click 150 -- Second Click 150 -- End of first Click 150 -- End of Second Click |
|
|
| Report Abuse |
|
|
BowtieMod
|
  |
| Joined: 01 Apr 2013 |
| Total Posts: 804 |
|
| |
|
LucasLua
|
  |
| Joined: 18 Jun 2008 |
| Total Posts: 7386 |
|
|
| 06 Jan 2015 06:43 PM |
Use this:
local rand = math.random(100, 200)
By using the "local" keyword, the variable will only be "visible" within its scope. Since its scope is within the function "click", another run of the function "click" running at the same time as the other "click" function will not be able to see or use this variable. |
|
|
| Report Abuse |
|
|
opplo
|
  |
| Joined: 09 Dec 2008 |
| Total Posts: 5320 |
|
|
| 06 Jan 2015 06:43 PM |
| Doesn't retain it to that execution of the function. I want it local to that specific execution so when I run the function again it doesn't change it for other ongoing executions. |
|
|
| Report Abuse |
|
|
opplo
|
  |
| Joined: 09 Dec 2008 |
| Total Posts: 5320 |
|
|
| 06 Jan 2015 06:45 PM |
Oh sorry it does work, my bad. That's odd i'm sure i tried it before and it didn't work.
Thank you anyway. |
|
|
| Report Abuse |
|
|
|
| 06 Jan 2015 06:46 PM |
so you want a random number
and then you want to keep that random number? |
|
|
| Report Abuse |
|
|
|
| 06 Jan 2015 06:46 PM |
| oh good, i was like, that should work |
|
|
| Report Abuse |
|
|