You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I want to get instance using ModuleScript -
What is the issue? Include screenshots / videos if possible!
It return nil instead of the instance that I wanted
And anyways, here is the screenshot
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
My solution doesn’t work, If you’re wondering what is my solution then.
-- This is just a fraction of the code
FindSomething.FoundedStuff = nil
if Child.Name == Stuff then
print(Child.Name, "has been found at "..Child.Parent.Name.." and the service that it was found at is "..Service.Name..". Deep Search attempts : "..DeepSearchAttempts)
DeepSearchAttempts = 0
if ReturnIt ~= false then
FindSomething.FoundedStuff = Child
return FindSomething.FoundedStuff
else
break
end
else
DeepSearch(Child, UsingName, ReturnIt, Stuff, Service)
end
And also I have tried looking for solutions
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
Sorry for the messy script, I don’t have time to clean it up.
ModulueScript :
local FindSomething = {}
FindSomething.Services = {
game:GetService("Workspace"),
game:GetService("ServerStorage"),
game:GetService("ServerScriptService"),
game:GetService("Players"),
game:GetService("ReplicatedStorage"),
game:GetService("StarterGui")
}
FindSomething.DeepSearchAttempts = 0
local function GiveStuff()
end
local function DeepSearch(SomeStuff, UsingName, ReturnIt, Stuff, Service)
FindSomething.DeepSearchAttempts += 1
if UsingName ~= false then
if #SomeStuff:GetChildren() > 0 then
for _, Child in pairs(SomeStuff:GetChildren()) do
if Child.Name == Stuff then
print(Child.Name, "has been found at "..Child.Parent.Name.." and the service that it was found at is "..Service.Name..". Deep Search attempts : "..FindSomething.DeepSearchAttempts)
FindSomething.DeepSearchAttempts = 0
if ReturnIt ~= false then
print(Child)
return Child
else
break
end
else
DeepSearch(Child, UsingName, ReturnIt, Stuff, Service)
end
end
end
else
if #SomeStuff:GetChildren() > 0 then
for _, Child in pairs(SomeStuff:GetChildren()) do
if Child == Stuff then
print(Child.Name, "has been found at "..Child.Parent.Name.." and the service that it was found at is "..Service.Name..". Deep Search attempts : "..FindSomething.DeepSearchAttempts)
FindSomething.DeepSearchAttempts = 0
if ReturnIt ~= false then
return Child
else
break
end
else
DeepSearch(Child, UsingName, ReturnIt, Stuff, Service)
end
end
end
end
end
local function Search(Stuff, UsingName, ReturnIt)
if UsingName ~= false then
for _, Service in pairs(FindSomething.Services) do
for _, Child in pairs(Service:GetChildren()) do
if Child.Name == Stuff then
print(Child.Name, "has been found at "..Service.Name..".")
if ReturnIt ~= false then
return Child
else
break
end
else
DeepSearch(Child, UsingName, ReturnIt, Stuff, Service)
end
end
end
else
for _, Service in pairs(FindSomething.Services) do
for _, Child in pairs(Service:GetChildren()) do
if Child == Stuff then
print(Child.Name, "has been found at "..Child.Parent.Name..".")
if ReturnIt ~= false then
return Child
else
break
end
else
DeepSearch(Child, UsingName, ReturnIt, Stuff, Service)
end
end
end
end
end
function FindSomething:Find(Stuff)
return Search(Stuff, false, false)
end
function FindSomething:FindUsingName(Stuff)
return Search(Stuff, true, false)
end
function FindSomething:FindAndReturnIt(Stuff)
return Search(Stuff, false, true)
end
function FindSomething:FindUsingNameAndReturnIt(Stuff)
local ItemFound = Search(Stuff, true, true)
print("From Function" , ItemFound)
return ItemFound
end
return FindSomething
Script :
local FindSomething = require(game.ReplicatedStorage:FindFirstChild("FindSomething"))
local YourMother = FindSomething:FindUsingNameAndReturnIt("YourMother")
print(YourMother)
print(YourMother.Name, "has died.")
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
Please tell me if this topic is in the wrong category.