local Rolelist = { ["Mafia"] = 1, ["Doctor"] = 2, ["Jailor"] = 3 } local Role = Instance.new("IntValue", plr) Role.Name = "Role" Role.Value = 0 local function random2() local number = math.random(1, #Rolelist) repeat number = math.random(1, #Rolelist) until (not roleUsed[number]) roleUsed[number] = true Rolelist.Value = number end random2()
What am I doing wrong?
I don't believe you've provided the full script; so I don't know where the line 19 quoted in the title is.
I hope maybe by rewriting this section I can help others understand this more.
local RoleUsed = {} local RoleList = {} RoleList["Mafia"] = 1 RoleList["Doctor"] = 2 RoleList["Jailer"] = 3 local IntValue = Instance.new("IntValue") IntValue.Name = "Role" IntValue.Value = 0 IntValue.Parent = plr local function random2() local n = math.random(1, #RoleList) repeat n = math.random(1, #RoleList) until not RoleUsed[n] RoleUsed[n] = true IntValue.Value = n end random2()
This is the full script
local used = {} local roleUsed = {} local Rolelist = { ["Mafia"] = 1, ["Doctor"] = 2, ["Jailor"] = 3 } game.Players.PlayerAdded:Connect(function(plr) local Id = Instance.new("IntValue", plr) Id.Name = "Id" Id.Value = 0 local Role = Instance.new("IntValue", plr) Role.Name = "Role" Role.Value = 0 local function random2() local number = math.random(1, #Rolelist) repeat number = math.random(1, #Rolelist) until (not roleUsed[number]) roleUsed[number] = true Rolelist.Value = number end local function random() local number = math.random(1, 8) repeat number = math.random(1, 8) until (not used[number]) used[number] = true Id.Value = number end random() random2() end)