Service argument not detecting right?

REPRO FILE: ReproFile.rbxl (18.7 KB)

So, basically, I’m creating a lazy module to use and search for objects/folders:

function Module:Event(Service, Obj1, Obj2)
	print(Service, "1")
	print(Obj1, "2")
	print(Obj2, "3")
	if Service ~= workspace then bla bla bla
		if not Obj2 then
			return Service:WaitForChild(Obj1)
		elseif Obj2 then
			return Service:WaitForChild(Obj1):WaitForChild(Obj2) -- please spare me from using WaitForChild excessivley
		end
	end
end

On script calling module and using function:

local Data = Events.Search(RepStorage, "Modules", "Data") -- goes to rep storage, finds modules, finds data inside modules

(Read the comments to understand)
Basically, what it is supposed to do is go to the service and search for the object name then search again for inside that object.

However, the issue arising is that when printing it out, it would be like this instead:

Modules 1
Data 2
nil 3

For some reason, it completely ignores the fact that the service argument exists, pushes the arguments down by 1 value, AND has a weird tendacy if done correctly, to actually go to

if not Obj2 then
	return Service:WaitForChild(Obj1)

even though, as seen in the print message above ^, argument 3/result comes back as nil?!??

I know I must be doing something wrong though I actually have no clue even when reading the countless of output messages.

Any reason as to why this is occuring?

1 Like

While there seems to be drastic amounts of code missing to give a full explanation as to why this may be occurring, if it is skipping over one value, why not just insert a placeholder value?

function Module:Event(_,Service, Obj1, Obj2)
1 Like

I’ve provided all the code that I’ve found to have issues currently with, nothing else is interfering with it even when deleted, still same problem/action.

Also, addin a placeholder value seems like a band-aid solution even if it does work? It doesn’t explain the reason why it is happening :thinking:

There is clearly a missing error considering you haven’t provided a snippit of code that actually uses your Module:Event function.

And while it is a band-aid solution, it is the best I can give you without the aforementioned code using Module:Event.

This is the code which can be found in the post:

local RepStorage = game:GetService("ReplicatedStorage")
local Module = require(RepStorage:WaitForChild("EventModule"))

local Data = Module.Event(RepStorage, "Modules", "Data") -- goes to rep storage, finds modules, finds data inside modules

Inside repstorage is simply a folder called “Modules” and inside the “Modules” folder is “Data”

Thats literally it

1 Like

I must be failing to notice how “Events.Search” is equivalent to “Module:Event”, once again with that inconsistency it feels like there is a missing piece to the puzzle.

Sorry about that, forgot to paste in the other part, updated it with what it actually is.

For debugging purposes, perhaps replace the (Service, Obj1, Obj2) part of the script with (...) and printing ... to get a result of what is actually being sent through the function.

I opened up the .rbxl file that you sent along with this, and I edited the script a bit. Is this the type of output message you wanted to see?

image

Events Edited.rbxl (18.7 KB)

1 Like

Now I’m more confused then ever, I changed your edit to be nearly the exact same as the above ^ and now it works?

local Module = {}

function Module.Event(Service, Obj1, Obj2)
	if Service ~= workspace then
		if not Obj2 then
			return Service:WaitForChild(Obj1)
		elseif Obj2 then
			return Service:WaitForChild(Obj1):WaitForChild(Obj2)
		end
	end
end

return Module

:man_shrugging:, Thanks though :+1:

1 Like

The only part that I changed was the line when you were creating the function.

image

Instead of,

function Module:Event()

-- I changed it to:

function Module.Event()