SkyeKun
6/1/2019 - 3:06 AM

Class Module

This allows you to create a class system in lua or rbx.lua

--[[
	Author: Skye
--]]

class = function(userdata)

	local meta = setmetatable({}, {
		
		__index = function(self, k)
			if type(userdata[k]) == "function" then
				local fake = function(...)
					local results
					if typeof(userdata) == "Instance" then
						local service = game:GetService(userdata.Name)
						results = service[k](service, ...)
					else
						results = userdata[k](...)
					end
					return results
				end
				return fake
			end
			return userdata[k]
		end,
		
		__call = function(self, ...)
			
			if self["Init"] then
				self:Init(...)
			end
			
			return self
			
		end
		
		
	})


	return meta

end

return class
--[[
	Author: Skye
--]]
 
local modules = script.Parent
local class = require(modules.Core.Class)
local DataStore = require(modules.Core.DataStore)
 
local Players = class(game:GetService('Players'))


Players.Added = function(Player)
	print(Player.Name, "has joined")
end
 
Players.Removing = function(Player)
	print(Player.Name, "has left")
end

function Players:Init(self) -- Players object
	
	self.PlayerAdded:Connect(self.Added)
	self.PlayerRemoving:Connect(self.Removing)
	
end
 

return Players