It’s kind of long
local Players = game:GetService("Players")
local RP = game:GetService("ReplicatedStorage")
local RemoteEvents = RP:WaitForChild("RemoteEvents")
local UpdateStatsEvent = RemoteEvents:WaitForChild("UpdateStats")
local UpdateSettings = RemoteEvents:WaitForChild("SettingsChangedRequest")
local ProfileService = require(RP:WaitForChild("ThirdParty"):WaitForChild("ProfileService"))
local TypeClass = require(RP:WaitForChild("Classes"):WaitForChild("Item"):WaitForChild("Types"))
local PlayerClass = {}
PlayerClass.__indext = PlayerClass
local CONFIG = require(script.CONFIG)
local ProfileStore = ProfileService.GetProfileStore(
"4y3y3y5y53dfgsds",
CONFIG.Template
)
local Profiles = {}
local ConvertTable = {
["number"] = "IntValue",
["string"] = "StringValue",
["boolean"] = "BoolValue",
}
local Exludes = {"NukeCount", "NukeCountDown", "TradeCount", ""}
local function Minutes(Number)
return Number * 60
end
local function Hours(Number)
return Number * 3600
end
local function GetGiftTime(Number)
return ({
Minutes(5),
Minutes(5),
Minutes(7),
Minutes(8),
Minutes(7),
Minutes(10),
Minutes(10),
Minutes(10),
Minutes(10),
Minutes(10),
Minutes(10),
Minutes(10),
})[Number]
end
local function ShouldReset(lastReset)
return os.time() - lastReset >= 86400
end
function PlayerClass.new(Player)
local Profile = ProfileStore:LoadProfileAsync("Player_" .. Player.UserId)
if Profile then
Profile:AddUserId(Player.UserId)
Profile:Reconcile()
Profile:ListenToRelease(function()
Profiles[Player] = nil
Player:Kick()
end)
if Player:IsDescendantOf(Players) == true then
Profiles[Player] = Profile
PlayerClass:AddLeaderstats(Player)
PlayerClass:UpdateGiftTimer(Player, Profile)
local Placements = Profile.Data.Placements
for i, v in Profile.Data.HotbarItems do
local ItemType = TypeClass.GetWeaponType(v)
RP:WaitForChild("RemoteEvents"):WaitForChild("AddHotbarItem"):FireClient(Player, v, ItemType, nil, Placements)
end
UpdateSettings:FireClient(Player, Profile.Data.Settings)
task.spawn(function()
while task.wait(1) do
--PlayerClass:HandleXP(Player, Profile, 100)
end
end)
--PlayerClass:Update(Player, "💎 Diamond", 50000000)
--PlayerClass:Update(Player)
else
Profile:Release()
end
else
Player:Kick()
end
end
function PlayerClass:AddLeaderstats(Player)
local Profile = Profiles[Player]
if not Profile then -- used for laggy players or bad internet
repeat
Profile = Profiles[Player]
task.wait(0.3)
until Profile
end
local Ld = Instance.new("Folder")
Ld.Name = "leaderstats"
Ld.Parent = Player
local t = Instance.new("Folder")
t.Name = "Other"
t.Parent = Player
if not Player.Character then
repeat
task.wait()
until Player.Character
end
for i, v in Profile.Data do
local ValueType = typeof(v)
if ValueType == "table" or table.find(Exludes, i) then continue end
local ValueT = Instance.new(ConvertTable[ValueType])
if ValueT then
ValueT.Name = i
ValueT.Value = v
ValueT.Parent = if i == "XP" or i == "XPToNextLevel" then t else Ld
UpdateStatsEvent:FireClient(Player, ValueT.Name, ValueT.Value)
end
end
end
function PlayerClass:HandleXP(Player, Profile, Amount: number)
local XP = Profile.Data.XP
local Level = Profile.Data["⭐️ Level"]
local XPToNextLevel = Profile.Data.XPToNextLevel
XP+=Amount
while XP >= XPToNextLevel do -- 120 >= 120
XP -= XPToNextLevel -- 120 - 120 = 0
Level += 1
XPToNextLevel = math.floor(20 + Level * 50)
task.wait(0.1)
end
PlayerClass:Update(Player, "XP", XP)
PlayerClass:Update(Player, "XPToNextLevel", XPToNextLevel)
if Profile.Data["⭐️ Level"] == Level then return end -- make sure to not update level if it didn't change
PlayerClass:Update(Player, "⭐️ Level", Level)
end
function PlayerClass:UpdateGiftTimer(Player: Player, Profile)
task.spawn(function()
repeat
task.wait()
until Player.Character -- prevents loop from running until the character loads
while true do
for x = 1, 12 do
local CurrentTime = Profile.Data.GiftSystem.GiftTimers[x] or GetGiftTime(x)
Profile.Data.GiftSystem.GiftTimers[x] = CurrentTime
RemoteEvents.GiftUpdate:FireClient(Player, x, {TimeLeft = Profile.Data.GiftSystem.GiftTimers[x], Claimed = Profile.Data.GiftSystem.ClaimedGifts[x]})
Profile.Data.GiftSystem.GiftTimers[x] -= 1
Profile.Data.GiftSystem.GiftTimers[x] = math.clamp(Profile.Data.GiftSystem.GiftTimers[x], 0, math.huge)
end
task.wait(1)
end
end)
end
function PlayerClass:Update(Player: Player, Key: string, Value: number)
local Profile = Profiles[Player]
if not Profile then return end
Profile.Data[Key] = Value
local ld = Player:WaitForChild("leaderstats")
local Other = Player:WaitForChild("Other")
UpdateStatsEvent:FireClient(Player, Key, Value)
if ld:FindFirstChild(Key) then
ld[Key].Value = Profile.Data[Key]
elseif Other:FindFirstChild(Key) then
Other[Key].Value = Profile.Data[Key]
else
return
end
end
function PlayerClass:GetProfileData(Player)
local Profile = Profiles[Player]
repeat task.wait()
Profile = Profiles[Player]
until Profile
return Profile
end
function PlayerClass:ReleaseProfile(Player)
if Profiles[Player] then
local Profile = Profiles[Player]
Profile:Release()
end
end
return PlayerClass