game:GetService('RunService').Stepped:Connect(function() wait() for i,v in pairs(workspace:GetDescendants()) do --when i add this part in --whatever here doesnt matter end end)
Instead of spam checking the whole workspace to see if anything was added, you can instead use the .DescendantAdded event, which is much more efficient.
Here’s how your code would look like with the event :
game.Workspace.DescendantAdded:Connect(function(instance) --Not sure if just workspace.DescendantAdded would work so I put game.Workspace instead if instance.Name == StringToMatchHere then --Stuff happens end end)
What makes this easier is that the event would return the instance that was added, so you don’t need to go use a for loop to search through what was added.
Hope this helped!
x = 1 --or whatever you want but not too small while true do wait(x) for i,v in pairs(workspace:GetDescendants()) do --whatever here doesn't matter end end
Now you aren't doing loads of stuff every frame only every second
EDIT: Denny9876's answer is better than my one