If I do a local function in a while true do loop how do I prevent the memory leak?

while true do
local function thingy(haha)

thingy = nil

I don’t want there to be like 20 thingy functions after 20 seconds yknow

just put the functions outside the loop, problem solved

You don’t need to set thingy to nil. Luau’s VM will automatically remove the function from the stack and it will eventually be garbage collected (unless it is an active upvalue).