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

Tried to make random map system.but it throws an error attempt to index nil with 'Name'. What to do?

Asked by 2 years ago

Server script (in serverscriptservice):


local lobby_Duration = 10 local round_Duration = 10 local maps = game:GetService('ReplicatedStorage'):WaitForChild('Map'):GetChildren() local timerval = game.ReplicatedStorage:WaitForChild("TimerValue") local function RTimer () while wait() do for l = lobby_Duration, 0, -1 do timerval.Value = 'Intermission: '..l wait(1) if l == 0 then local map = maps[math.random(#maps, 1)] -- change to your map name timerval.Value = 'Teleporting players to '..map.Name wait(1) map.Parent = workspace local players = game.Players:GetChildren() for i = 1, #players do players[i].Character:MoveTo(Vector3.new(-122.5, 55.5, -41.5)) end wait(1) for g = round_Duration,0, -1 do timerval.Value = 'Round '..g..' seconds left' wait(1) if g == 0 then timerval.Value = 'Round over' wait(2) timerval.Value = 'Teleporting players to lobby' wait(1) for i = 1, #players do players[i].Character:MoveTo(Vector3.new(-122.5, 55.5, 2.5)) end map.Parent = maps wait(1) -- repeat again end end end end end end spawn(RTimer)

1 answer

Log in to vote
0
Answered by 2 years ago

The reason for this is on the line where you choose a random map, math.random should have a min argument that is lesser than the max argument, you are doing the opposite, that's why it's not choosing a map and returning nil, the fix would probably be to swap the two values

if l == 0 then
    local map = maps[math.random(1, #maps)] -- this is the problem
    nametimerval.Value = 'Teleporting players to '..map.Name
    -- Your code
0
Then it returns an error invalid argument #2 to 'random' (interval is empty) Br0kenM1ndss 7 — 2y
0
Could it be line 3 where you havent defined what map is? im talking about ' local maps = ' iRedStoneCraftYT 0 — 2y
0
@Br0kenM1ndss that means that your maps folder has 0 children (maps) inside it AnasBahauddin1978 715 — 2y
Ad

Answer this question