Hi guys, I'm TheLorizz and I don't know why but the math.randoms I put doesn't work, why? This is the first time!
I need to select a traitor and a detective from the innocents array, but the output gives me this on "math.random()" lines:
bad argument #2 to 'random' (interval is empty)
This is the code:
local players = game.Players:GetChildren()
local innocents = {}
local traitor
local detective
function findType(p)
local td = p:FindFirstChild("TempData")
local type = td:FindFirstChild("Type")
return type
end
_G.startGame = function()
local h = Instance.new("Hint", game.Workspace)
h.Text = "Selecting traitor!"
wait(2)
for i, player in pairs (players) do
table.insert(innocents, player)
local type = findType(player)
type.Value = "Innocent"
wait()
end
wait(1)
traitor = innocents[math.random(1, #innocents)]
local ttype = findType(traitor)
ttype.Value = "Traitor"
table.remove(innocents, traitor)
h.Text = "Traitor selected:" .. " " .. traitor
wait(1)
h.Text = "Selecting detective!"
detective = innocents[math.random(1, #innocents)]
local dtype = findType(detective)
dtype.Value = "Detective"
table.remove(innocents, detective)
h.Text = "Detective selected:" .. " " .. detective
wait(1)
h.Text = "Game started!"
end
Why? I repeat, this is the first time!

1 comment
local players = game.Players:GetChildren() that's why! I don't update this variable, THANKS!