Attempt to get length of a Instance value

for i, v in pairs(workspace.GeneratedRooms:GetChildren()) do
	randomRoom = math.random(1, #v) -- attempt to get length of a Instance value 
if randomRoom and CanSpawnArcane.Value == true then
	ArcaneModule.SpawnSpider(workspace.Arcanes.Nest, randomRoom)
	print("Spawned Spider")

I don’t know how to fix this issue, if anyone knows please help.
workspace.GeneratedRoom:GetChildren() is a model, if that helps.

(there is more script above, but i don’t think it needs to do with the problem)

Any help is appreciated!


Simple question that you should state its answer in your topic.

Anyways, the error describes itself, “attempt to get length of a Instance value”, the # character is typically used to get the length of an array (element count) or a string (character count) but you are instead, using the hashtag character with an instance value (something is not countable) willing to get a number.

Let me know the first question’s answer up there to be able to help you further.


the v in GetChildren is an Instance while i is the index holding the Instance., do you mean this?

local children = workspace.GeneratedRooms:GetChildren()
local randomRoom = children[math.random(1, #children)]

Thank you! This worked perfectly, I don’t think I would’ve thought of that!

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