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

Any good tutorial on the function children()?

1 answer

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.

:

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)

3 comments

0

I like your script examples. But you should probably explain what the letters mean. Like for q,r in pairs(table) do something

0

Alright i'll edit it, look at it again.

0

Well ofcourse i messed up on the point that using names insted of userid's but it's just an example.

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