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

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

Asked by 4 years ago

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.

0
math.random(min,max) always returns a numer value marijus06 68 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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

0
thank you, it worked! PicoTheRiko 34 — 4y
Ad

Answer this question