Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

If GetChildren() == nil then?

So basically I'm making a minigame's game, which has a certain gamemode which removes plates randomly. I have that all working, but there are layers of plates and depending on the time, another layer will start to fade away, like this:

if MapClone.Name == "Classic" then
	for i = 60, 1, -1 do
		Timer.Value = i
		wait()
		if i <= 35 then
		DMud()
		else
		DGrass()
		end
	end
end

So the:

if i <= 35 then

tells the script if it is below or equal to 35 then run the function DMud() [Fade away another layer], but I want it so the layer under the top layer starts to fade away BEFORE it is completely gone. I know how to do this, but the problem is the script will give an error because the function cannot find anything it is trying to destroy.

Is there a way to do, if the children in a model is nothing (empty) so it has no children then.. blah.. blah blah.

I hope you can help.

1 answer

✓ Accepted answer

There is a way!

local childrenInObject = object:GetChildren() --returns a table
if #childrenInObject == 0 then --checking table length, table.getn(table) is deprecated
--code here
end

3 comments

0

Thanks, is there anyway you can stop a function?

0

What do you mean by "stop a function?" I think I understand what you mean, but I can't really think of any situation where you would need to.

0

The function that is called, randomly makes the grass/mud dissappear. But if there is none left in the GetChildren() then it will crash and the entire script breaks, was wondering if you could do thr check, then stop the rest of the function.

This discussion is preserved as it was. New answers, comments, and votes are closed.