Error says parent property is locked

I have a system that spawns clouds with a folder inside it. When the clouds are destroyed, the folders in the cloud gets transferred to the workspace.

The code works as intended, although, I got an error that says the folder’s parent property is locked.
This occurred right when I stopped the game so I’m not sure what it did.

My goal is to figure out why the error appeared, how did it affect the game, and how could I prevent it.

Function from the error (Picture of Error Code Below):

local function handlePatataSpawning(cloud, cloudType)
	local amountOfPatatas = 0
	local patata = getPatataByCloudType(cloudType)
	local patataFolder = cloud:FindFirstChild("PatataFolder")
	
	task.spawn(function()
		moveCloud(cloud)
	end)
	
	
	repeat
		wait(.25)
		
		if math.random(1, 2) == 1 then
			amountOfPatatas += 1
			createNewPatata(patata, cloud)
		end
	until amountOfPatatas >= maxPatatas
	
	patataFolder.Parent = workspace -------- The problem that occured
	
	cloud:Destroy()
	cloudsInPlay -= 1
end

Are you destroying the “PatataFolder” at any point? I may be wrong, but I believe that issue occurs when you try to parent it while it is being deleted.

2 Likes

I have a script that deletes empty folders so that it clears folders that aren’t in use.

Oh yeah! All I needed to do was to make sure to not delete the folders that are in the clouds! Thanks a lot!

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