Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

If GetChildren() == nil then?

Asked by
iFlusters 355 Moderation Voter
9 years ago

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

Log in to vote
1
Answered by
yumtaste 476 Moderation Voter
9 years ago

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
0
Thanks, is there anyway you can stop a function? iFlusters 355 — 9y
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. yumtaste 476 — 9y
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. iFlusters 355 — 9y
Ad

Answer this question