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

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

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!

2 comments

1

You can make a function to return math.random(10,15) ie local random = function() return math.random(10,15) end

0

OK! Will try.

1 answer

✓ Accepted answer

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 :).

1 comment

0

Yh, I think I'll try that! Thanks!

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