How can i achieve this? I could just put a script inside of each part but that would cause massive amounts of lag. I have a folder inside of another folder located in the workspace.
How can i get all parts in the folder?
How can i achieve this? I could just put a script inside of each part but that would cause massive amounts of lag. I have a folder inside of another folder located in the workspace.
How can i get all parts in the folder?
That is unnecessary.
ServerScriptService:
db = false -- This is important so the Code doesnt spam
for number, index in pairs(ExampleFolder:GetChildren()) do -- goes through the "Folders" Instances
if index:IsA("Part") then -- if found objects is under the class of part
print(number) -- prints number of Instances found that are under this condition
index.Touched:Connect(function(hit) -- Applys a Connection to all Instances under that condition
if not db then -- if db is false
db = true -- Event cant be used
print(hit.Transparency) -- prints the transparency of the part that it touched
task.wait(1) -- delay
db = false -- Event can be used
end
end)
end
end
This is a great way to reduce the amount of Resources the Server uses
CollectionService just Applys a tag that can be used later or other tasks, its a bit unnessacary for this case as the Table is Applying a Connection to stuff under a Condition, it can be useful here when you want to disconnect the Event.
Instead of having a Script for one Killbrick, you can have the Server go through itself and Apply those Connections to the objects under a specified condition (Sorry if I repeat this word)
If you’re saying that you have folder-ception, or multiple folders inside of multiple folders, you can easily just use a recursive function. This is assuming that is the case, of course.
local folder = game.Workspace[your folder here]
function loopfolder(item)
for _, v in pairs(item:GetChildren()) do
if v:IsA("Folder") then
loopfolder(v)
elseif v:IsA("Part")
v.Transparency = .5 -- your transparency here
end
end
end
loopfolder(folder)
@Sepruko This isn’t true,
Touched events only fire when the Object is moving, or has detected a Collusion, when not moving, Detector or Detected, it wont fire, unless there is a change, either by another collusion or movement, I think you may be confusing GetTouchingParts here.
Its called a Debounce, its use to yield code from firing too many times (A Cooldown), plus, it wont effect any code below the Event, I’m not sure where you are going at here.
The Post clearly says task.wait()
Your code would give a 1 sec waiting time to all parts once one is touched. A dictionary denounce is all that would be needed. It still yields in an event listener, but I’m not sure why this would be a big issue.
Last edit was 6 hours ago, you posted then 5 hours ago, i did originally use wait(), but a few minutes later I switched to task.wait()
@Sepruko The first 2 edits contained wait, the third had task.wait(), other than that minor spelling checks and then clarifying on more details
another alternative to this would be to have Bool Attributes as a debounce, but that might cause issues
Who said that I was offended, or that you were attacking me? I was only stating on why i disagreed on some parts, I’m not sure at what point you thought that.
Can you elaborate a bit on why yielding in an event listeren is a bad idea? What kind of problems will you run into, or how?