Using type checking in this scenario

Hi, I made a knit controller and I am wondering if there is any bad habits inside this module i made.

It’s for zones and it uses zoneplus.

Also, I want to start using typechecking but I need help with it. Is it possible for any of you guys to add type checking?

Latest Edit

local CollectionService = game:GetService("CollectionService")
local TweenService = game:GetService("TweenService")

local Knit = require(game:GetService("ReplicatedStorage").Packages.Knit)
local Zone = require(game:GetService("ReplicatedStorage").Source.Zone)

local Tag = "Zone"

local Connections = {}
local Zones = Knit.CreateController{
	Name = "ZoneController"
}

local function accessZone(instance: Instance, player: Player)
	if not player.Character then
		return
	end
	
	local accessTween = TweenService:Create(instance,TweenInfo.new(
		1,
		Enum.EasingStyle.Sine,
		Enum.EasingDirection.Out
		),
		{
			Transparency = 1,
			--Color = Color3.fromRGB(0, 181, 0)
		}
	)
	
	instance.Transparency = 0.2
	instance.Color = Color3.fromRGB(0, 181, 0)
	accessTween:Play()
end

local function leaveZone(instance: Instance, player: Player)
	if not player.Character then
		return
	end
	
	local leaveTween = TweenService:Create(instance,TweenInfo.new(
		1,
		Enum.EasingStyle.Sine,
		Enum.EasingDirection.Out
		),
		{
			Transparency = 1,
			--Color = Color3.fromRGB(189, 34, 44)
		}
	)
	
	instance.Transparency = 0.2
	instance.Color = Color3.fromRGB(189, 34, 44)
	
	leaveTween:Play()
end

local function DestroyConnections(t)
	print(Connections)

	for i, v in pairs(Connections) do
		if typeof(v) == "RBXScriptConnection" and v.Connected then
			v:Disconnect()
			Connections[i] = nil
		end
	end
end

local function playerLeft()
	DestroyConnections(Connections)
	end
	
function Zones:KnitStart()
	-- for now this is empty...
end

function Zones:KnitInit()
	print(script.Name,"Initialized")
	
	for _, instance in ipairs(CollectionService:GetTagged(Tag)) do
		if instance:IsA("Part") then
			local newZone = Zone.new(instance)
			
			local access = newZone.playerEntered:Connect(function(player)
				accessZone(instance, player)
			end)
			
			local leave = newZone.playerExited:Connect(function(player)
				leaveZone(instance, player)
			end)

			table.insert(Connections, access)
			table.insert(Connections, leave)
		end
	end

	game.Players.PlayerRemoving:Connect(playerLeft)
end

return Zones
7 Likes