Opinions on zone module?

I’ve been working on my own zone module for fun, and just wanted to know if there was anything I could do differently. Thanks!

local module = {}
module.__index = module

function module.NewZones(Container: Folder)
	local self = setmetatable({}, module)
	self.Name = Container.Name
	self.PlayerEntered = Instance.new("BindableEvent")
	self.PlayerLeft = Instance.new("BindableEvent")
	self.Zones = Container:GetChildren()
	self.Touches = 0
	return self
end

function module:CheckForTouch()
	local touchingPlayers = {}
	local function getPlayer(part: BasePart)
		return game.Players:GetPlayerFromCharacter(part.Parent)
	end
	local function inList(tbl, obj)
		return table.find(tbl, obj)
	end
	game:GetService("RunService").Stepped:Connect(function()
		local tempPlayers = {}
		if not self.Zones then return end
		for _,zone: Part in self.Zones do
			local parts = workspace:GetPartBoundsInBox(zone.CFrame, zone.Size)
			for _, part in parts do
				local player = getPlayer(part)
				if player and not inList(tempPlayers, player) then
					table.insert(tempPlayers, player)
					if not inList(touchingPlayers, player) then
						self.PlayerEntered:Fire(player)
						self.Touches += 1
					end
				end
			end
		end
		for _,plr in touchingPlayers do
			if not inList(tempPlayers, plr) then
				self.PlayerLeft:Fire(plr)
			end
		end
		touchingPlayers = tempPlayers
	end)
end


function module:GetEvents()
	return {
		Entered = self.PlayerEntered.Event,
		Left = self.PlayerLeft.Event
	}
end

function module:GetTouchNumber()
	return self.Touches
end

function module:Delete()
	self.PlayerEntered:Destroy()
	self.PlayerLeft:Destroy()
	self.Zones = nil
end

return module

Well, i have not looked into it that well, but i see you made 2 functions in a function which you could easily put outside the function. This will save performance, because you don’t create 2 new function every time you call it.

Ah, just saw that too. Thanks for replying!

Ye, i also recommend to get rid of the runservice.stepped or adding a delay. I dont think you need to check every frame or do you?

So you’re saying to use a while loop with a task.wait() in there instead of a Runservice.Stepped?

No, just use deltatime and a variable. Then just add the deltatime to the variable everytime it runs till it is at a sertaint delay (1-5 seconds probably).