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

Can I have a temporary variable for math.random(x,y)?

Asked by 7 years ago

It's kinda simple I think.

Essentially, is this possible

local random = math.random(10,15)

-- use random later

hum.WalkSpeed = hum.WalkSpeed - random

That's first of all.

Second of all, will that variable stay as one assigned variable? Say, if math.random pulls out 14, will it stay as 14 when I do:

hum.WalkSpeed = hum.WalkSpeed - random

In addition, if this is in a function which only runs when it's hit, does random change again?

Thanks!

1
You can make a function to return math.random(10,15) ie local random = function() return math.random(10,15) end User#5423 17 — 7y
0
OK! Will try. DerpyShadowz 34 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

Yes it is possible, but I would advise you to add this;

math.randomseed(tick())

on the very top of your script. This code will randomize your math.random() code and not make it the same everytime.

I do not know about the Second of all, will that variable stay as one assigned variable? Say, if math.random pulls out 14, will it stay as 14 when I do: but adding math.randomseed(tick()) on the very top of your script helps a lot. Hope this helped :).

0
Yh, I think I'll try that! Thanks! DerpyShadowz 34 — 7y
Ad

Answer this question