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

Any good tutorial on the function children()?

Asked by 4 years ago

So I want to learn about the children functions. But I can't find a good tutorial explaining it. Does anyone have any good site or video to learn it?

0
Use GetChildren() ... Children() is depreciated https://developer.roblox.com/en-us/api-reference/function/Instance/GetChildren ForeverBrown 356 — 4y
1
If you know how to use tables and iterating through them, then GetChildren should be easy for ya :) ForeverBrown 356 — 4y

1 answer

Log in to vote
0
Answered by
VitroxVox 884 Moderation Voter
4 years ago
Edited 4 years ago

Hello there, well as @ForeverBrown said Roblox's GetChildren source is really useful, but like you said you want a "good tutorial" well i can't really give you that but, however, i can give you an example of an GetChildren action here:

Counting how many parts are in the workspace:

for n,p in pairs(workspace:GetChildren()) do
    print("There's:",n,"Parts in the workspace")
end

As well as removing everything from a: Model,Part,Folder,Etc:

for _,g in pairs(workspace:GetChildren()) do
    g:Destroy()
end

But there's an easier way to do that unless you want to remove not everything but only parts, or values or something like that then you'd have to do an if statement like this:

for _,p in pairs(game.Players:GetPlayers()) do
    if p:IsA("Player") then
    print"ok he a player"
    end
end

^^^ Well ofcourse it's a player but you get it.

Also there's functions like > :ClearAllChildren which is really useful.

<Working with tables>:

local admins = {"zetruis","testsubject2"}


for _,adminlist in pairs(admins) do
    if (adminlist=game.Players.LocalPlayer.Name) then
    print"You're an admin!"
else
    print"Sorry you're not an admin!
    end
end

Yes i know i used a localscript as an example but here's an serverscript example same as that ^^

local admins = {"zetruis","testsubject2"}

game.Players.PlayerAdded:Connect(function(p)

for _,adminlist in pairs(admins) do
    if (adminlist=p.Name) then
    print"You're an admin!"
else
    print"Sorry you're not an admin!
    end
end

end)
0
I like your script examples. But you should probably explain what the letters mean. Like for q,r in pairs(table) do something voidofdeathfire 148 — 4y
0
Alright i'll edit it, look at it again. VitroxVox 884 — 4y
0
Well ofcourse i messed up on the point that using names insted of userid's but it's just an example. VitroxVox 884 — 4y
Ad

Answer this question