I was recently coding a module, and I noticed a keyword called self. I saw some of my friends use self as a variable when they coded a module. They also used it in functions. what is the purpose of self?
I was looking through the developer forum and the developer hub, but I didn’t find any solutions.
There was someone that made an anticheat module like this.
Anticheat example
This text will be hidden
local self = setmetatable({ClassName = "CharacterBind"}, CharacterBind)
self.Hooks = {}
self.Character = character
self.Player = PlayersService:GetPlayerFromCharacter(character)
self.Torso = torso
self.RootJoint = self.Torso:FindFirstChild("RootJoint") or character.LowerTorso.Root
self.Humanoid = humanoid
self.DiagnosticsFolder = character.FJsMovementAnticheat
self.OnPunishment = self.DiagnosticsFolder.OnPunishment
self.LastCFrame = self.Torso.CFrame
self.LastGoodCFrame = self.Torso.CFrame
self.LastGroundedAltitude = self.Torso.CFrame.Position.Y
self.SpeedHeat = 0
self.FlightHeat = 0
self.VelocityHeat = 0
self.IsBeingPunished = false
self.CriticalCharacterComponents = {
self.Humanoid,
self.Torso,
self.Torso:FindFirstChild("RootJoint") or character.LowerTorso.Root,
}
any help is appreciated