The module:
local ExtraFunctions = {}
local CollectionService = game:GetService("CollectionService")
function ExtraFunctions.GetGrandParent(Object:Instance)
if Object == nil or not Object:IsA("Instance") or Object == game then
warn("Error , Function :- GetGrandParent , Reason :- Object is not an Inastance or is nil , nil returned.")
return nil
end
if Object.Parent and Object.Parent.Parent then
return Object.Parent.Parent
else
return nil
end
end
function ExtraFunctions.GetObjectsWithName(Name:string , Parent:Instance)
if Name == nil or Parent == nil or type(Name) ~= "string" or not Parent:IsA("Instance") then
warn("Error , Function :- GetObjectsWithName , Reason :- Name is not string or is nil or Parent is not an Inastance or is nil , nil returned.")
return nil
end
if #Parent:GetChildren() > 0 then
local Table = {}
for i , Object in pairs(Parent:GetChildren()) do
if Object.Name == Name then
table.insert(Table , Object)
end
end
if #Table > 0 then
return Table
else
return nil
end
else
return nil
end
end
function ExtraFunctions.GetObjectsFromType(Type:string , Parent:Instance)
if Type == nil or Parent == nil or type(Type) ~= "string" or not Parent:IsA("Instance") then
warn("Error , Function :- GetObjectsFromType , Reason :- Type is not string or is nil or Parent is not an Inastance or is nil , nil returned.")
return nil
end
if #Parent:GetChildren() > 0 then
local Table = {}
for i , Object in pairs(Parent:GetChildren()) do
if Object:IsA(Type) then
table.insert(Table , Object)
end
end
if #Table > 0 then
return Table
else
return nil
end
else
return nil
end
end
function ExtraFunctions.GetPlayerMains(Player:Player)
if Player == nil or not Player:IsA("Player") then
warn("Error , Function :- GetPlayerMains , Reason :- Player is nil or Player is not a player , nil returned.")
return nil
end
local Character = Player.Character or Player.CharacterAdded:Wait()
if Character then
local Humanoid = Character:FindFirstChild("Humanoid")
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
if Humanoid and Humanoid:IsA("Humanoid") and Humanoid.Health > 0 and HumanoidRootPart and HumanoidRootPart:IsA("BasePart") then
local Table = {
["Character"] = Character,
["Humanoid"] = Humanoid,
["HumanoidRootPart"] = HumanoidRootPart,
["UserId"] = Player.UserId,
}
return Table
else
return nil
end
else
return nil
end
end
function ExtraFunctions.SetValuesToValue(Values:{} , Value)
if Values == nil or type(Values) ~= "table" or #Values < 1 or (type(Value) ~= "number" and type(Value) ~= "string" and type(Value) ~= "boolean") then
warn("Error , Function :- SetValuesToValue , Reason :- the Values table is empty , note only (Int , Float , Boolean , String is supported) , nil returned.")
return nil
end
for i , value in pairs(Values) do
if value:IsA("IntValue") and type(Value) == "number" and Value % 1 == 0 then
value.Value = Value
elseif value:IsA("BoolValue") and type(Value) == "boolean" then
value.Value = Value
elseif value:IsA("NumberValue") and type(Value) == "number" then
value.Value = Value
elseif value:IsA("StringValue") and type(Value) == "string" then
value.Value = Value
end
end
end
function ExtraFunctions.AddAttribute(Objects:{} , Name:string , Value:any)
if Objects == nil or type(Objects) ~= "table" or #Objects < 1 or type(Name) ~= "string" or Value == nil or typeof(Value) == "Instance" then
warn("Error , Function :- AddAttribute , Reason :- the Objects table is empty or Name is not a string or Value is nil , nil returned")
return nil
end
for i , Object:Instance in pairs(Objects) do
if Object:IsA("Instance") and Object ~= game then
Object:SetAttribute(Name , Value)
end
end
end
function ExtraFunctions.RemoveAttribute(Objects:{} , Name:string)
if Objects == nil or type(Objects) ~= "table" or #Objects < 1 or type(Name) ~= "string" then
warn("Error , Function :- AddAttribute , Reason :- the Objects table is empty or Name is not a string , nil returned")
return nil
end
for i , Object:Instance in pairs(Objects) do
if Object:IsA("Instance") and Object ~= game then
Object:SetAttribute(Name , nil)
end
end
end
function ExtraFunctions.Tag(Objects:{} , Name:string)
if Objects == nil or type(Objects) ~= "table" or #Objects < 1 or type(Name) ~= "string" then
warn("Error , Function :- Tag , Reason :- the Objects table is empty or Name is not string , nil returned")
return nil
end
for i , Object in pairs(Objects) do
if Object:IsA("Instance") and Object ~= game then
CollectionService:AddTag(Object , Name)
end
end
end
function ExtraFunctions.RemoveTag(Objects:{} , Name:string)
if Objects == nil or type(Objects) ~= "table" or #Objects < 1 or type(Name) ~= "string" then
warn("Error , Function :- Tag , Reason :- the Objects table is empty or Name is not string , nil returned")
return nil
end
for i , Object in pairs(Objects) do
if Object:IsA("Instance") and Object ~= game and Object:HasTag(Name) then
CollectionService:RemoveTag(Object , Name)
end
end
end
function ExtraFunctions.SetName(Objects:{} , Name:string)
if Objects == nil or type(Objects) ~= "table" or #Objects < 1 or type(Name) ~= "string" then
warn("Error , Function :- SetName , Reason :- the Objects table is empty or Name is not string , nil returned.")
return nil
end
for i , Object in pairs(Objects) do
if Object:IsA("Instance") and Object ~= game then
Object.Name = Name
end
end
end
function ExtraFunctions.SetParent(Objects:{} , Parent:Instance)
if Objects == nil or type(Objects) ~= "table" or #Objects < 1 or Parent == nil or not Parent:IsA("Instance") or Parent == game then
warn("Error , Function :- SetParent , Reason :- the Objects table is empty or Parent is nil , nil returned.")
return nil
end
for i , Object in pairs(Objects) do
if Object:IsA("Instance") and Object ~= game then
Object.Parent = Parent
end
end
end
function ExtraFunctions.SetColor(Objects:{} , Color:Color3)
if Objects == nil or type(Objects) ~= "table" or #Objects < 1 or typeof(Color) ~= "Color3" then
warn("Error , Function :- SetColor , Reason :- Objects table is empty or Color is nil , nil returned")
return nil
end
for i , Object:Instance in pairs(Objects) do
if Object:IsA("BasePart") then
Object.Color = Color
end
end
end
function ExtraFunctions.SetCFrame(Objects:{} , Cframe:CFrame)
if Objects == nil or type(Objects) ~= "table" or #Objects < 1 or typeof(Cframe) ~= "CFrame" then
warn("Error , Function :- SetCFrame , Reason :- Objects table is empty or CFrame is nil , nil returned")
return nil
end
for i , Object:Instance in pairs(Objects) do
if Object:IsA("BasePart") then
Object.CFrame = Cframe
end
end
end
return ExtraFunctions
I’ve been there before too years ago when I was just starting out. I made a module with a few thousand lines of code, and it was just like this. Extra functions. I was so proud, but nobody cared about it. It’s because something like this is not particularly useful as each individual function is either very easy to code or is redundant/unnecessary. Coding anything is good practice though!