So I am working on a module where it uses OOP to create a .new another one of my functions would need to use .new to to create a new object. My code is below
local OQUO = {}
OQUO.__index = OQUO
function OQUO:GetColor(color)
local colorstring = tostring(string.lower(color))
if colorstring == "red" then
return Color3.fromRGB(255,0,0)
elseif colorstring == "green" then
return Color3.fromRGB(0,255,0)
elseif colorstring == "blue" then
return Color3.fromRGB(0,0,255)
elseif colorstring == "black" then
return Color3.fromRGB(163, 162, 165)
elseif colorstring == "orange" then
return Color3.fromRGB(255, 170, 0)
elseif colorstring == "pink" then
return Color3.fromRGB(255, 0, 255)
elseif colorstring == "purple" then
return Color3.fromRGB(170, 0, 255)
elseif colorstring == "teal" then
return Color3.fromRGB(0, 255, 255)
elseif colorstring == "white" then
return Color3.fromRGB(255, 255, 255)
elseif colorstring == "yellow" then
return Color3.fromRGB(255, 255, 0)
end
end
function errors(msg)
warn("~~~~~~~~~~~~~~~~~~~~~~~~~~~\nOQUO Extention Error:\n" .. msg .. "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~")
end
function check(light)
if string.sub(string.lower(light.Name), 1, 6) == "parcan" then
return true
else
return false
end
end
local alllighting = {}
for i,v in ipairs(workspace:GetChildren()) do
if check(v) then
table.insert(alllighting, v)
end
end
function OQUO.new(tble)
local info = tble
setmetatable(info, OQUO)
return info
end
function OQUO:On()
for _,light in ipairs(self) do
if check(light) then
local Head = light:WaitForChild("Head")
Head:WaitForChild("Filter"):WaitForChild("SurfaceLight").Enabled = true
Head:WaitForChild("B"):WaitForChild("Beam").Enabled = true
Head:WaitForChild("Light").Material = Enum.Material.Neon
else
errors(light.Name .. " is not a valid OQUO lighting kit")
end
end
end
function OQUO:Off()
for _,light in ipairs(self) do
if check(light) then
local Head = light:WaitForChild("Head")
Head:WaitForChild("Filter"):WaitForChild("SurfaceLight").Enabled = false
Head:WaitForChild("B"):WaitForChild("Beam").Enabled = false
Head:WaitForChild("Light").Material = Enum.Material.Metal
else
errors(light.Name .. " is not a valid OQUO lighting kit")
end
end
end
function OQUO:Color(color)
for _,light in ipairs(self) do
if check(light) then
local Head = light:WaitForChild("Head")
Head:WaitForChild("Filter"):WaitForChild("SurfaceLight").Color = color
Head:WaitForChild("B"):WaitForChild("Beam").Color = ColorSequence.new(color)
else
errors(light.Name .. " is not a valid OQUO lighting kit")
end
end
end
function OQUO.RandomLight()
local chosenlight = alllighting[math.random(1, #alllighting)]
local info = {chosenlight}
setmetatable(info, OQUO)
return info
end
function OQUO:Brightness(value)
for _,light in ipairs(self) do
if check(light) then
local Head = light:WaitForChild("Head")
Head:WaitForChild("B"):WaitForChild("Beam").Transparency = NumberSequence.new(value, value)
else
errors(light.Name .. " is not a valid OQUO lighting kit")
end
end
end
return OQUO
the lines I am focusing on are the .new and randomlight. As you see I currentyl just copy and pasted what was in .new however I would rather just use the function within the module. How would I accomplish this?