Issue with wait() on getdescendants()

I’m trying to Optimise Dynamic Lighting by making a capped 5 lighting updated every frame
when frame reaches to 5 and there’s a wait it stops the thread with no errors at all

while true do
wait(0.3)
local cappedframe = 0
	for _,v in pairs(workspace:GetDescendants()) do
		cappedframe = cappedframe + 1
		if cappedframe >= 5 then
		cappedframe = 0
		wait()
        print("took a break")
	    end
    end
end

The Purpose to Optimise?
It minimizes the spike lag and makes FPS much smoother to have a processor a short break to prevent slowdown issues.

I tried to solve it, and I through it related to renderstepped:Wait() stopping a thread, but all wait() stops refreshes.

The given code works fine for me. I’m assuming this is a simplified version - what else are you doing in your script?

Getting Sound Occlusion, raycasting / muffle the audio, depending on how hard surface is
Getting Light with Variable, raycasting / getting location and how close light is, change range / beam
Getting World’s Audios, raycasting too / muffles the audio, depending on how hard surface is

Your issue is probably going to be in there somewhere. Only having that information, I can’t really work out where the problem would be. This didn’t happen before you capped the lighting updates per frame?

1 Like

When i added cappedframe value It’s stopped refreshing lights / sounds / others, it feels like it on wait forever by getdescendants even if i put cappedframe = 0 before wait()
image
Did i miss something?

Put a print somewhere in the loop to check if it’s still running?

1 Like


I did, i saw world muffle only be updated till i got out of the house and it stopped updating
others nothing else
I’ll figure out the cause of it