local chunkpieces = script.Parent.ChunkPieces:GetChildren("ChunkPiece") wait(0.5)--wait time after chunk is loaded to reduce lag for i = 1,25 do wait(0.1) if chunkpieces[i]:IsA("Model") and chunkpieces[i].Name == "ChunkPiece" then b = math.random(#chunkpieces) local randompart = chunkpieces[b] randompart.IsEnabled.Value = true end end
this script goes through a model which contains lots of other models, each of those other models is a group of parts. an error occurs and the for loop only runs once.
the error:
Workspace.AreaChunk3.CoreManager:6: attempt to index field '?' (a nil value)
local chunkpieces = script.Parent.ChunkPieces:GetChildren()--get children is a table and can not find a specific child wait(0.5)--wait time after chunk is loaded to reduce lag for i = 1,25 do wait(0.1) if chunkpieces[i]:IsA("Model") and chunkpieces[i].Name == "ChunkPiece" then b = math.random(#chunkpieces) local randompart = chunkpieces[b] randompart.IsEnabled.Value = true end end
Shouldn't it be:
b = math.random(1,#chunkpieces)
Also looping could be done by usi g #chunkpieces instead of 25