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

math.random value is always numbers instead of words from a table, am i doing something wrong?

i am making a random player chooser, a chosen player will get their name printed on the output, however, it prints out the number "1" out of a table instead of their name. the script is:

players = {}

local function onCharacterAdded(chr)
	table.insert(players, chr)
	local value = math.random(1,#players)
	print(value)
end


game.Players.PlayerAdded:Connect(onCharacterAdded)

i was going to give the chosen player a tool, however i don't know if it will work if its going to print out numbers.

1 comment

0

math.random(min,max) always returns a numer value

1 answer

✓ Accepted answer

If you want to select random players name from a table do this:

players = {}

local function onCharacterAdded(chr)
    table.insert(players, chr)
    local value = players[math.random(1,#players)]
    print(value)
end

game.Players.PlayerAdded:Connect(onCharacterAdded)

PS: You almost got it! Hoped it helps :D

1 comment

0

thank you, it worked!

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