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