I have a ModuleScript , and it have a function, and this function have piece of code that do somthigns in the children; of a model in workspace
And i have script inside every model that that require the ModuleScript
How i will access the children?
And i will have alot of these models, so i must use a ModuleScript in case i want to change somthing in the future
and As far as I know i must use script.Parent.TheNameOfThingIwant
I tried to describe what i need as best I can.
Please note that English is not my primary language. So sorry if there is unclear things (:
--ModuleScript
local module = {}
function module.Command(model)
for _, child in pairs(model:GetChildren()) do
print(child.Name)
end
end
return module
--Script
local model = workspace:WaitForChild("Model")
local module = require(game.ServerScriptService.ModuleScript)
module.Command(model) --or maybe module.Command(script.Parent)
Basically saying send the model as part of the parameters.
module.Command(model, A, B, C) – if needed.
The way I use the most is simply to create another module just for saving / reading the data you need that doesnt require neither of your other modules but instead is required by both of them.
Another more whacky way would be to instead of requiring the other module at the beginning, instead just create an empty variable for it and require + set it in a function you call only from one place, this way you’ll dodge the recursive call.
so the ModuleScript is under a folder under workspace
and that folder also have alot of models
there is a script under every model
and this script require the function in the ModuleScript
so how can i define the Humanoid or the Desc in the ModuleScript function?
here is the script inside the ModuleScript:
local module = {}
module.CheakingAvailability = function ()
local Outfit = script.Parent
local Humanoid = Outfit:FindFirstChildOfClass("Humanoid")
local Desc = Outfit:FindFirstChildOfClass("HumanoidDescription")
-- i want to do a piece of code here but how i can define the Outfit?
-- or the HumanoidDescription or the Humanoid
return module
This should make it easier to access each model outfits
Then inside the module script, iterate through each of the contents within that folder
for _, outfit in pairs(game.Workspace.OutfitFolder.Outfits) do
-- stuff you want to do for each outfit model
end
And that’s it. Easy to do.
Now let’s try to solve the question in the post you mentioned above ^
for _, outfit in pairs(game.Workspace.OutfitFolder.Outfits) do
-- the outfit is the model (Which is Outfit1, Outfit2, Outfit3... etc...)
outfit.Humanoid.NameDisplayDistance = None;
end
each block under the PlayerVision1(the one where it says slow)is manually looking up the location of each blocks every iteration, 4096 times which took about 120ms per frame.
And this is the one with cached memory:
(Well it looks like it was already solved so I guess I don’t have to write up a solution. Thanks to everyone as well for pitching in their solutions as well )