Attempt To Get Length of a Instance Value

I have loocked at a post and it said to use :GetChildern(). I can not figer out how to fix it.

Error:

  11:23:15.737  ServerScriptService.RoundScript:41: attempt to get length of a Instance value  -  Server - RoundScript:41

Line 41

local chosenMap = mapsFolder:GetChildren()[math.random(1, #mapsFolder)]:Clone()
1 Like

The length operator (#) gets array length, and mapsFolder is not an array. Assuming the list is not going to change (no new or removed maps during runtime), you can use GetChildren() to create an array of maps and keep chosing one randomly.

local maps = mapsFolder:GetChildren()
-- chose a map from the list
local chosenMap = maps[math.random(1, #maps)]:Clone()
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.