So I was working on a simple OOP module script that generates a Tohunga (Tohunga is just a species for one of my games), but the script just changes the base Tohunga model, when it’s supposed to clone the model, then change aspects of the cloned Tohunga model.
NOTE 1: This is my first use of OOP inside of roblox, so there are probably a lot of issues of the script that I haven’t figured out, I would rather you guys not modifiy my script, since I would like to learn more about OOP via coding, and not look at other people’s scripts, but if there are stuff like memory leaks, bad practices ect, then please notify me where they are occuring, and how to fix them.
Module script, inside of ServerScriptService:
local Tohunga = {}
Tohunga.__index = Tohunga
local partTypes = {
[1] = "BasePart",
[2] = "MeshPart",
[3] = "UnionOperation"
}
function setTohungaEyeStock(Model,EyeStockColor)
Model.FullHead.Head.EyeStock.Color = EyeStockColor
if Model.FullHead.Head.EyeStock:IsA(partTypes[3]) then
Model.FullHead.Head.EyeStock.UsePartColor = true
end
end
function setTohungaColor(Model,MainColor,SideColor,MaskColor)
for _,part in pairs(Model.UpperBody:GetDescendants()) do
if part:IsA(partTypes[1]) or part:IsA(partTypes[2]) or part:IsA(partTypes[3]) then
part.Color = MainColor
if part:IsA(partTypes[3]) then
part.UsePartColor = true
end
continue
end
end
for _,part in pairs(Model.LowerBody:GetDescendants()) do
if part:IsA(partTypes[1]) or part:IsA(partTypes[2]) or part:IsA(partTypes[3]) then
part.Color = SideColor
if part:IsA(partTypes[3]) then
part.UsePartColor = true
end
continue
end
end
Model.FullHead.Mask.Color = MaskColor
if Model.FullHead.Mask:IsA(partTypes[3]) then
Model.FullHead.Mask.UsePartColor = true
end
end
-- vv This part of the script is where the main issue is happening. vv
function Tohunga.GenerateTohunga(Model,Name,MainColor,SideColor,MaskColor,EyeStockColor,Anchored)
local newTohunga = {}
setmetatable(newTohunga,Tohunga)
newTohunga.Model = Model
newTohunga.Model.Name = Name
newTohunga.Model.MainColor.Value = MainColor
newTohunga.Model.SideColor.Value = SideColor
newTohunga.Model.MaskColor.Value = MaskColor
newTohunga.Model.EyeStockColor.Value = EyeStockColor
coroutine.wrap(function()
setTohungaColor(Model,MainColor,SideColor,MaskColor)
end)()
coroutine.wrap(function()
setTohungaEyeStock(Model,EyeStockColor)
end)()
for _,part in pairs(newTohunga.Model:GetDescendants()) do
if part:IsA(partTypes[1]) or part:IsA(partTypes[2]) or part:IsA(partTypes[3]) then
coroutine.wrap(function()
part.Anchored = Anchored
end)()
end
end
return newTohunga
end
-- ^^ Right above here is the function where the main issue is happening. ^^
function Tohunga:AddDialog(Dialog)
local dialogClone = Dialog:Clone()
dialogClone.Parent = self.Model.FullHead.Mask
end
function Tohunga:ChangeDialog(Dialog)
local dialogClone = Dialog:Clone()
for _,dialog in pairs(self.Model.FullHead.Mask:GetChildren()) do
if dialog:IsA("Dialog") then
dialog:Destroy()
continue
end
end
dialogClone.Parent = self.Model.FullHead.Mask
end
function Tohunga:SetTohungaParent(Parent)
self.Model.Parent = Parent
end
return Tohunga
NOTE 2: I know I never cloned the model in the module script, the reason why I didn’t is because I couldn’t figure out how I should go about cloning the model in a readable fashion, that also didn’t result in anything odd occurring.
Any help is appreciated!