I need to fix this error that pops up once the event is fired too much, but i got no clue how to fix it.
In my game, once the game loads in, some assets get cloned or copied into the workspace.
Having a limit to the workspace.DescendantAdded is making me unable to do this practice i mentioned above. If there’s better practice that i can replace and is more practical than the one i said above, please tell me so i change it!
If not, i need an idea of how to fix the event reaching the limit.
Thanks!
This is how i managed the game set up when loaded
local function setUpWorkspaceParts (part)
--[[just an example of what i'm doing
if part.Name == "name" then
ReplicatedStorage.Item:Clone().Parent = part.Parent
end]]
end
for i,workspaceObject in pairs(workspace:GetDescendants()) do
setUpWorkspaceParts(workspaceObject)
end
workspace.DescendantAdded:Connect(setUpWorkspaceParts)
local function setUpWorkspaceParts(part)
if part.Name == "name" then
ReplicatedStorage.Item:Clone().Parent = part.Parent -- this will run the function again because of the descendantadded event
end
end
workspace.DescendantAdded:Connect(setUpWorkspaceParts)
Not sure what you’re trying to do here but if you really want to, you can add the part to a blacklist so it doesn’t run the function over and over again:
local Blacklist = {}
local function setUpWorkspaceParts(part)
if part.Name == "name" and not table.find(Blacklist, part) then
local Clone = ReplicatedStorage.Item:Clone()
table.insert(Blacklist, Clone)
Clone.Parent = part.Parent
end
end