How do i fix this error?

Hiya Developers!

Not sure why, whenever this script runs, i get this error when it hits line 13?

	if i == 1 then
		timer.Value = "Randomizng A New Map!"
		task.wait(2)
		print("waited")
		local rand = math.random(1, #maps) --> Line 13
		local map = maps[rand]:Clone()
		map.Parent = workspace

		timer.Value = "Tester "..map.Name
		task.wait(4)
		local players = game.Players:GetChildren()
	end	
	
	
end


ServerScriptService.MainMainigame:13: attempt to get length of a Instance value

Any help is appreciated!

You most likely intended for it to be

local rand = math.random(1 #maps:GetChildren())

As your probably trying to get a random map which is a child of your maps folder in serverstorage/replicatedstorage(not recommended)

Why is it no recommended?

30 Limit

Putting your maps folder containing all your game maps in replicatedstorage specifically is not recommended because it takes up unnecessary client memory, so serverstorage should be used over it for containing things the server should be managing without client exploitation(Maps/ assets/ etc…)

1 Like

Doesn’t seem to work correctly?
image
Whenever i add a comma, like this, i get an error.
image
image

This line right here, your still indexing a numbervalue on an instance, instead of the array of it’s children. You’d need to define the maps folder’s children and then use it for picking a random map

local mapPool = maps:GetChildren()

local rand = math.random(1, #mapPool)
local chosenMap = mapPool[rand]
1 Like