Ported Functions

From Legacy Roblox Wiki
Jump to navigationJump to search
Work In Progress
This is currently being worked on! Check back later for more information... hopefully.


Modern versions of ROBLOX include many new features and functions which provide an easier experience for creators to make their own game. Because of this, older ROBLOX clients have far less features and therefore functions to offer. Fortunately, due to these limitations, ROBLOXians have — in the past, and in the now — made their own functions to serve the same purpose as their counterparts in the present.

WaitForChild

This function keeps cycling around the requested parent until a child with the requested name is found.

local function waitForChild(parent, name)
	while not parent:FindFirstChild(name, false) do
		wait(0.03)
	end

	return parent:FindFirstChild(name, false)
end

GetDescendants

This function is also considered a replacement to a very important function. It returns a table which contains all objects found within a requested object.

local function getDescendants(instance)
	local descendants = {}

	for i, v in ipairs(instance:GetChildren()) do
		table.insert(descendants, v)

		for j, w in ipairs(getDescendants(v)) do
			table.insert(descendants, w)
		end
	end

	return descendants
end

ClearAllChildren

Use this when working with releases before 49.

local function clearAllChildren(instance)
	for index, value in ipairs(instance:GetChildren()) do
		value:Remove()
	end
end

FindFirstAncestor

local function findFirstAncestor(instance, name)
	local ancestor = instance.Parent

	while ancestor and ancestor ~= game do
		if ancestor.Name == name then
			return ancestor
		else
			ancestor = ancestor.Parent
		end
	end

	return nil
end

FindFirstAncestorOfClass

local function findFirstAncestorOfClass(instance, className)
	local ancestor = instance.Parent

	while ancestor and ancestor ~= game do
		if ancestor.ClassName == className then
			return ancestor
		else
			ancestor = ancestor.Parent
		end
	end

	return nil
end

FindFirstChildOfClass

local function findFirstChildOfClass(instance, className)
	for index, value in ipairs(instance:GetChildren()) do
		if value.ClassName == className then
			return value
		end
	end

	return nil
end