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

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

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.

2 comments

1

that work for me... the problem is not here!

0

This is the whole script.

3 answers

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

1 comment

0

Sorry, both don't work.

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

1 comment

0

Nope. When I changed math.random(m) to math.random(1, m) the problem still occurs.

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.

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