My custom functions module 2.0 attempts to call a nil value on self:GetDescendants() and I really do not know much more to say other than I am trying to call it with a variable I do not know how to use self so good by the way sorry if this sucks game.Workspace.Baseplate
--ServerScript
local OOP_Script = require(script["OOP-Script"]) --// Please read the OOP-Script before using this
local Recursives = require(script.Recursives)
local MainModule = require(script.Parent)
local MainFunctions = require(script.MainFunctions)
local part = game.Workspace.Baseplate
part = MainFunctions:WaitForChildWhichIsA("ClickDetector")
print(MainModule.Variables.Thank_You)
--ModuleScript
local mainFunc = {}
function mainFunc:WaitForChildWhichIsA(class)
local descendants = self:GetDescendants()
if class and #descendants > 0 then
local findClass = self:FindFirstChildWhichIsA(class)
if findClass then repeat wait() until findClass elseif not findClass then wait(2) warn("Infinite Yield possible on " .. "'" .. findClass .. "'") end
return "Found Object"
end
end
return mainFunc
Youâre not quite grasping the problem here.
You have a âpartâ that you want to find a decendent of.
But youâre not running âWaitForChildâŚâ on the part, youâre running it on the module.
the part doesnât get checked for anything at all.
Your code might as well say this:
local part = game.Workspace.Baseplate
part = nil
Because the âMainFunctions:WaitForChildWhichIsA()â function isnât being passed the part at all.
It sounds like what youâre trying to achieve is something like this:
local part = game.Workspace.Baseplate
part:WaitForChildWhichIsA()
You will NOT be able to do this unless you either A) Somehow modify the default roblox API to extend the functions that are inherited by robloxâs âPartâ object. or B) Create your own new type of Part object and give it this function and then instantiate it.
Youâre going to just have to get over the idea of using an extra variable.
Passing the part in to a function is the best way to do this.
Your code would look like this instead:
local part = game.Workspace.Baseplate
local _type = "Click Detector" -- you can't use "type" as a variable as it already exists in the API namespace.
local part2 = MainFucntions.WaitForChildWhichIsA(part,_type)
It is possible, but you have to go about it a bit differently.
Those functions âGetPropertiesâ and âChangeSurfaceâ are hardcoded into the Roblox API, the only way to add your own function of this type is by extending the actual Part object in the roblox API or by creating your own version of part that has the functions you want in it.
You can do the later with something called a Factory Pattern. I think the functionality youâre looking for right now is a bit beyond the scope of what youâre trying to do, for at least the level youâre at. But youâre not wrong in wanting to do it that way, itâs just going to be easier for you to do it another way for now most likely.
Try to keep one response at a time, this isnât a chat, itâs a forum, other people will come and read this and by spamming multiple responses you edge out other peopleâs post. Just update your last post if you need to add more information or wait and type it all in one post.
But to answer your question, you need to do something called a Factory Pattern.
This will allow you to create a module which can make your own parts which have the functionality you desire.