Does my code look decent + any tips?

I started learning OOP around 2 hours ago and i need some opinions on the current code i have.
Does it look good and how can i improve it even further?

Touched Event Code:

local PartTouched = {}
PartTouched.__index = PartTouched

function PartTouched.new(obj: Part)
	local self = {}
	setmetatable(self, PartTouched)
	
	self.Increase = 1
	self.Part = obj
	self.Connection = obj.Touched:Connect(function(hit)
		local Char = hit:FindFirstAncestorWhichIsA("Model")
		self.Player = game.Players:GetPlayerFromCharacter(Char)
		if Char then
			local Humanoid = Char:FindFirstChild("Humanoid")
			if Humanoid then
				self:Ignite()
			end
		end
	end)
	return self
end

function PartTouched:Ignite()
	local Points = self.Player:FindFirstChild("leaderstats").points
	Points.Value += self.Increase
	self.Connection:Disconnect()
	self.Part:Destroy()
end

return PartTouched

leaderstats:

local Points = {}
Points.__index = Points

function Points.new(Player: Players)
	local self = {}
	setmetatable(self, Points)
	
	self.plr = Player
	self:Leaderstats()
	return self
end

function Points:Leaderstats()
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = self.plr
	
	local points = Instance.new("IntValue")
	points.Name = "points"
	points.Parent = leaderstats
end

return Points

Its hard to discern what utility is added by using OOP in such a short example. It seems good in that it follows the book recommendations for how to share functions associated with an object. Please be careful with OOP as its has the potential to create a huge mess very quickly when compared to the classical approach of passing only the neccessary info back and forth between one function at a time. In particular OOP can get you into trouble via: Fragility (Lua’s way of doing OOP is especially prone to this), Spooky Action, and thread safety.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.