So, I am currently making a script for implementing a profile class using OOP, and I made a function on updating the old data of a joining player whenever the values in the profile table get updated.
It seems to work just fine, but I was wondering whether I could improve upon this current script and try to optimise it.
Here is the code:
local profile = {}
profile.__index = profile
function profile.new(player, self)
repeat task.wait() until player.Character ~= nil
if self then return setmetatable(self, profile) end --if another profile is sent as a param (self), then return metatable for that profile
local self = setmetatable({}, profile)
self.Name = player.Name
self.Character = player.Character or player.CharacterAdded:Wait()
self.Rank = player:GetRoleInGroup(2568175)
self.BanProfile = {
IsBanned = false,
UnbanDate = nil,
StaffWhoBanned = nil
}
return self
end
function profile:SetCharacter(character)
self.Character = character
end
function profile:SetName(name)
self.Name = name
end
function profile:UpdateData(player)
local oldProfile = self
if self.BanProfile.IsBanned == true then
error("Error: could not update player data, player is banned")
else
local self = profile.new(player)
for i,v in ipairs(oldProfile) do
self[v] = oldProfile[v]
end
return self
end
end
--ill add more functions here in the future lol
return profile
If you need any extra info about the script, I am welcome to give it to you. Thanks