Open source code troubleshooting

Hi there everyone. I’m in a dev team with 5 others working on an open source game (an open world survival game) that was made during 2011, and was just recently fixed. More specifically, we are creating a new variant of the game set in the sky (using the fixed version’s components) as a passion project and we are running into issues with the resource system as we update the game.

Here’s what’s causing the issue:
image

and here’s part of the script with the functions that were (possibly?) involved with said line (line 7-13):

local Load = require(game.ReplicatedStorage:WaitForChild("Load"))

local DataAccessor = Load "Data.DataAccessor"

----------------------------------------

----- Objects --------------------------

----------------------------------------

local resourceRoot = workspace.Resources

Line 30-52:

local function ChooseRandomChild(root)
	local children = root:GetChildren()
	
	if #children == 0 then
		return nil
	end
	
	math.randomseed(tick())
	
	return children[math.random(1, #children)]
end

local function ResolveCluster(cluster)
	local chosen = ChooseRandomChild(cluster)
	
	for _, child in ipairs(cluster:GetChildren()) do
		if child ~= chosen then
			child:Destroy()
		end
	end
	
	chosen.Parent = resourceRoot
end

I am by no means to most people a Lua “professional” so I’m extremely lost with trying to figure out what’s wrong here. This is breaking the respawn system within the same core script as displayed and I need it fixed asap as it is game breaking. Could anyone help me to solving this issue somehow (example code would be appreciated if possible)?

Try to print chosen and try to print chosen.Parent

There are only two ways ChoseRandomChild can return nil: it either indexes outside of the children table (which is impossible) or the root has no children. Since your chosen variable is turning up as nil I can only assume the cluster is an instance that has no children, or whatever the chosen is, is destroyed somewhere in another script.

Using prints to see what your variables are at different stages should provide a bit more information.

1 Like

I think this is happening because ChooseRandomChild is unable to get a child because the provided root has no children. The function was called from inde ResolveCluster with the provided cluster being the root given to ChooseRandomChild.

TL;DR: cluster has no children.

1 Like