Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

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

Asked by
DesertusX 430 Moderation Voter
6 months ago
Edited 2 months 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 — 6mo
0
This is the whole script. DesertusX 430 — 6mo

3 answers

Log in to vote
1
Answered by 6 months ago
Edited 6 months 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 430 — 6mo
Ad
Log in to vote
1
Answered by 6 months 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 430 — 6mo
Log in to vote
0
Answered by
DesertusX 430 Moderation Voter
6 months ago
Edited 6 months 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