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

[SOLVED] Why does this script that gets a random member in an array not work?

Asked by
DesertusX 435 Moderation Voter
4 years ago
Edited 3 years ago

So, I made a script that gets a random member from an array. Its parent is a StringValue in workspace. I don't get any errors in the output. Can anyone help? Thanks for helping.

moves = {"move1"; "move2"; "move3"; "move4"; "move5"; "move6"}

function r(m)
    return math.random(m)
end


s = r(#moves)

selected = moves[s]

print(selected)

script.Parent.Value = selected

Once again, thanks for helping. It is really appreciated.

1
that work for me... the problem is not here! Mr_m12Ck53 105 — 4y
0
This is the whole script. DesertusX 435 — 4y

3 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

I am not a professional at scripting just starting on new stuff but 100% these might not work so try


moves = {"move1"; "move2"; "move3"; "move4"; "move5"; "move6"} function r(m) return math.random(m) end s = r(#moves) selected = moves[s] print(selected) script.Parent.random.Value = selected

And if this doesnt work try using this


moves = {"move1"; "move2"; "move3"; "move4"; "move5"; "move6"} function r(m) return math.random(m) end s = r(#moves) selected = moves[s] print(selected) script.Parent.moves.Value = selected
0
Sorry, both don't work. DesertusX 435 — 4y
Ad
Log in to vote
1
Answered by 4 years ago

when you are using math.random() you need to give min number and max number

0
Nope. When I changed math.random(m) to math.random(1, m) the problem still occurs. DesertusX 435 — 4y
Log in to vote
0
Answered by
DesertusX 435 Moderation Voter
4 years ago
Edited 4 years ago

It turns out the problem was it was accidentally a LocalScript. I'm very sorry to everybody who took their time to test the script and answer the question. To apologise, I will upvote all the answers and comments.

Answer this question