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

ServerScriptService.Values:19: invalid argument #2 to 'random' (interval is empty) ?

Asked by 4 years ago
01local Rolelist = {
02    ["Mafia"] = 1,
03    ["Doctor"] = 2,
04    ["Jailor"] = 3
05}
06    local Role = Instance.new("IntValue", plr)
07    Role.Name = "Role"
08    Role.Value = 0
09    local function random2()
10        local number = math.random(1, #Rolelist)
11 
12        repeat
13            number = math.random(1, #Rolelist)
14        until (not roleUsed[number])
15 
View all 21 lines...

What am I doing wrong?

0
can you put your full script or a little more? line 19 is blank from what you sent BulletproofVast 1033 — 4y
0
try printing RoleList right before line 19, see what is inside of it. Benbebop 1049 — 4y
0
maybe the table is supposed to be something like local Rolelist = {'Mafia', 'Doctor', 'Jailor'} (without the = Number) BulletproofVast 1033 — 4y
0
After testing it, for some reason its counting Rolelist as having zero entries. Maybe cause its a dictionary and not an array, but I don't remember that sort of behaviour being a thing. Benbebop 1049 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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.

01local RoleUsed = {}
02local RoleList = {}
03 
04RoleList["Mafia"] = 1
05RoleList["Doctor"] = 2
06RoleList["Jailer"] = 3
07 
08local IntValue = Instance.new("IntValue")
09IntValue.Name = "Role"
10IntValue.Value = 0
11IntValue.Parent = plr
12 
13local function random2()
14    local n = math.random(1, #RoleList)
15    repeat
View all 22 lines...
Ad
Log in to vote
0
Answered by 3 years ago

This is the full script

01local used = {}
02local roleUsed = {}
03 
04local Rolelist = {
05    ["Mafia"] = 1,
06    ["Doctor"] = 2,
07    ["Jailor"] = 3
08}
09game.Players.PlayerAdded:Connect(function(plr)
10 
11    local Id = Instance.new("IntValue", plr)
12    Id.Name = "Id"
13    Id.Value = 0
14 
15    local Role = Instance.new("IntValue", plr)
View all 44 lines...

Answer this question