Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local PlayerDataService = {}
- local DataStores2 = require(script.DataStore2)
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local Players = game:GetService("Players")
- local RunService = game:GetService("RunService")
- local PlayerCollection = {}
- local userDataStoreName = "TestingDataStore1"
- local DefaultData = {
- Name = "N/A",
- UserId = 0,
- HP = { -- Formula: [BASE HP] + ( ( [LEVEL] * [LEVEL MULTIPLIER] ) + ( [HP POINTS] * [HP POINT MULTIPLIER] ) )
- Base = 1000,
- Multiplier = {
- Level = 40,
- Point = 53
- }
- },
- Stamina = { -- [BASE STAMINA] + ( ( [LEVEL] * [LEVEL MULTIPLIER] ) + ( [STAMINA POINTS] * [POINT MULTIPLIER] ) )
- Base = 100,
- Current = 100,
- Max = 100,
- Multiplier = {
- Level = 5,
- Point = 5
- }
- },
- Level = {
- Current = 1,
- Prestige = 0,
- EXP = 0,
- Multiplier = 100,
- Max = 300,
- },
- RedeemedCodes = {},
- ["Stats"] = {
- Health = 0, -- HP
- Strength = 0, -- Damage
- Dexterity = 0, -- Accuracy + Crit Rate
- Quirk = 0, -- Accuracy + Crit Rate
- Stamina = 0, -- Stamina
- Points = 3
- },
- Traits = {
- Selected = 128911039142763,
- TraitStorage = {}
- },
- MoveSlots = {
- Slot1 = "",
- Slot2 = "",
- Slot3 = "",
- Slot4 = "",
- Slot5 = "",
- Slot6 = "",
- Slot7 = "",
- Slot8 = "",
- },
- CustomChar = {
- Hair1 = "Hair1",
- Hair1Color = "0 0 0",
- Hair2 = "Hair1",
- Hair2Color = "0 0 0",
- Shirt = 2774526319,
- Pants = 4763486305,
- Face = 0,
- SkinColor = "1 0.86 0.52",
- Customized = false
- },
- Quirk = {
- Ability = "Quirkless",
- Stores = {},
- Multiplier = 1000,
- Max = 100
- },
- Yen = 0,
- Spins = {
- Common = 3,
- Uncommon = 0,
- Rare = 0,
- PlusUltra = 0
- },
- Faction = "Civilian",
- Fame = 0,
- GymTime = 0,
- ExpTime = 0,
- YenTime = 0,
- Arena = {
- Wins = 0,
- Loses = 0,
- TotalTime = 0,
- ABSW = 0,
- },
- Inventory = {}
- }
- function StringToColor(String)
- local command = (String):split(" ")
- local R = nil
- local G = nil
- local B = nil
- for i, v in pairs(command) do
- if i == 1 then
- R = tonumber(v)
- elseif i == 2 then
- G = tonumber(v)
- elseif i == 3 then
- B = tonumber(v)
- end
- end
- return Color3.new(R,G,B)
- end
- function DeepTransfer(orig, targeted)
- targeted["Level"]["Max"] = orig["Level"]["Max"]
- for i, child in pairs(orig) do
- local child_type = type(child)
- if child_type == 'table' then
- for v, child2 in pairs(child) do
- local child2_type = type(child2)
- if child2_type == 'table' then
- for h, child3 in pairs(child2) do
- if targeted[i][v][h] == nil then
- targeted[i][v][h] = child3
- end
- end
- else
- if targeted[i][v] == nil then
- targeted[i][v] = child2
- end
- end
- end
- else
- if targeted[i] == nil then
- targeted[i] = child
- end
- end
- end
- end
- function DeepCopy(orig, copies)
- copies = copies or {}
- local orig_type = type(orig)
- local copy
- if orig_type == 'table' then
- if copies[orig] then
- copy = copies[orig]
- else
- copy = {}
- copies[orig] = copy
- for orig_key, orig_value in next, orig, nil do
- copy[DeepCopy(orig_key, copies)] = DeepCopy(orig_value, copies)
- end
- setmetatable(copy, DeepCopy(getmetatable(orig), copies))
- end
- else -- number, string, boolean, etc
- copy = orig
- end
- return copy
- end
- function PlayerDataService.ManualSave(Player)
- local PlayerId = Player.UserId
- if PlayerCollection[PlayerId] ~= nil then
- local PlayerData = PlayerCollection[PlayerId]
- DataStores2(userDataStoreName, Player):Set(PlayerData)
- PlayerDataService.UpdateInstances(Player)
- end
- end
- function PlayerDataService.new(playerid)
- if PlayerCollection[playerid] then
- return PlayerCollection[playerid]
- end
- local PlayerData = DeepCopy(DefaultData)
- PlayerCollection[playerid] = PlayerData
- local Player = game.Players:GetPlayerByUserId(playerid)
- local userData = DataStores2(userDataStoreName, Player):Get(PlayerData)
- coroutine.resume(coroutine.create(function()
- while wait(10) do
- DataStores2(userDataStoreName, Player):Set(userData)
- end
- end))
- coroutine.resume(coroutine.create(function()
- game.Players.PlayerRemoving:Connect(function(plr)
- if plr.Name == Player.Name then
- DataStores2(userDataStoreName, Player):Set(userData)
- end
- end)
- end))
- DeepTransfer(PlayerData, userData)
- PlayerCollection[playerid] = userData
- coroutine.resume(coroutine.create(function()
- if userData.CustomChar.Customized == false then
- game.ReplicatedStorage.DataSystem.TpToCustomization:FireClient(Player)
- end
- end))
- return userData
- end
- function UpdateInstance(InstanceData,path, key, value)
- local _instance = nil
- if path then
- _instance = InstanceData:FindFirstChild(path)
- if _instance then
- _instance = _instance:FindFirstChild(key)
- end
- else
- _instance = InstanceData:FindFirstChild(key)
- end
- if _instance then
- _instance.Value = value
- end
- end
- function PlayerDataService.UpdateInstances(Player)
- local PlayerData = PlayerDataService.new(Player.UserId)
- local InstanceData = Player:WaitForChild("InstanceData")
- if PlayerData.Quirk["Stores"] == nil then
- PlayerData.Quirk["Stores"] = {}
- end
- if PlayerData.Quirk.Stores[PlayerData.Quirk.Ability] == nil then
- PlayerData.Quirk.Stores[PlayerData.Quirk.Ability] = {}
- end
- if PlayerData.Quirk.Stores[PlayerData.Quirk.Ability]["Level"] == nil then
- PlayerData.Quirk.Stores[PlayerData.Quirk.Ability]["Level"] = 1
- end
- if PlayerData.Quirk.Stores[PlayerData.Quirk.Ability]["Exp"] == nil then
- PlayerData.Quirk.Stores[PlayerData.Quirk.Ability]["Exp"] = 0
- end
- UpdateInstance(InstanceData,"Level", "Current", PlayerData.Level.Current)
- UpdateInstance(InstanceData,"Level", "EXP", math.floor(PlayerData.Level.EXP))
- UpdateInstance(InstanceData,"Level", "RequiredEXP", math.floor(PlayerData.Level.Current * PlayerData.Level.Multiplier))
- UpdateInstance(InstanceData,"Stats", "Health", PlayerData.Stats.Health)
- UpdateInstance(InstanceData,"Stats", "Points", PlayerData.Stats.Points)
- UpdateInstance(InstanceData,"Stats", "Stamina", PlayerData.Stats.Stamina)
- UpdateInstance(InstanceData,"Stats", "Strength", PlayerData.Stats.Strength)
- UpdateInstance(InstanceData,"Stats", "Quirk", PlayerData.Stats.Quirk)
- UpdateInstance(InstanceData,"Quirk", "Ability", PlayerData.Quirk.Ability)
- UpdateInstance(InstanceData,"Quirk", "Level", PlayerData.Quirk.Stores[PlayerData.Quirk.Ability]["Level"])
- UpdateInstance(InstanceData,"Quirk", "EXP", PlayerData.Quirk.Stores[PlayerData.Quirk.Ability]["Exp"])
- UpdateInstance(InstanceData,nil, "MaxHealth", PlayerData.HP.Base + ( ( PlayerData.Level.Current * PlayerData.HP.Multiplier.Level ) + ( PlayerData.Stats.Health * PlayerData.HP.Multiplier.Point ) ) )
- UpdateInstance(InstanceData,"Stamina", "Max", PlayerData.Stamina.Base + ((PlayerData.Level.Current * PlayerData.Stamina.Multiplier.Level) + (PlayerData.Stats.Stamina * PlayerData.Stamina.Multiplier.Point)))
- UpdateInstance(InstanceData,"Stamina", "Current", PlayerData.Stamina.Current)
- UpdateInstance(InstanceData,"Stats", "Points", PlayerData.Stats.Points)
- UpdateInstance(InstanceData,nil, "Yen", PlayerData.Yen)
- UpdateInstance(InstanceData,"Spins", "Common", PlayerData.Spins.Common)
- UpdateInstance(InstanceData,"Spins", "Uncommon", PlayerData.Spins.Uncommon)
- UpdateInstance(InstanceData,"Spins", "Rare", PlayerData.Spins.Rare)
- UpdateInstance(InstanceData,"Spins", "PlusUltra", PlayerData.Spins.PlusUltra)
- UpdateInstance(InstanceData,nil, "EXPTime", PlayerData.ExpTime)
- UpdateInstance(InstanceData,nil, "YenTime", PlayerData.YenTime)
- Player:WaitForChild("leaderstats"):WaitForChild("Fame").Value = PlayerData.Fame
- end
- --if RunService:IsServer() then
- game.Players.PlayerAdded:Connect(function(Player)
- Player.CharacterAdded:Connect(function(Character)
- coroutine.resume(coroutine.create(function()
- local PlayerData = PlayerDataService.new(Player.UserId)
- PlayerDataService.UpdateInstances(Player)
- Character.Shirt.ShirtTemplate = "http://www.roblox.com/asset/?id=" .. PlayerData.CustomChar.Shirt
- Character.Pants.PantsTemplate = "http://www.roblox.com/asset/?id=" .. PlayerData.CustomChar.Pants
- Character.Head.Face.Texture = "http://www.roblox.com/asset/?id=" .. PlayerData.CustomChar.Face
- local SkinColor = PlayerData.CustomChar.SkinColor
- Character.Skin.HeadColor3 = StringToColor(SkinColor)
- Character.Skin.LeftArmColor3 = StringToColor(SkinColor)
- Character.Skin.RightArmColor3 = StringToColor(SkinColor)
- Character.Skin.RightLegColor3 = StringToColor(SkinColor)
- Character.Skin.LeftLegColor3 = StringToColor(SkinColor)
- Character.Skin.TorsoColor3 = StringToColor(SkinColor)
- local Hair1 = game.ReplicatedStorage.ModuleScript.AllAsssets.Hairs:FindFirstChild(PlayerData.CustomChar.Hair1):Clone()
- Hair1.Parent = Character
- local Hair1Color = PlayerData.CustomChar.Hair1Color
- Hair1.Handle.Color = StringToColor(Hair1Color)
- local Hair2 = game.ReplicatedStorage.ModuleScript.AllAsssets.Hairs:FindFirstChild(PlayerData.CustomChar.Hair2):Clone()
- Hair2.Parent = Character
- local Hair2Color = PlayerData.CustomChar.Hair2Color
- Hair2.Handle.Color = StringToColor(Hair2Color)
- end))
- if not Player:FindFirstChild("InstanceData") then
- local InstanceData = ReplicatedStorage:WaitForChild("Stats"):WaitForChild("InstanceData"):Clone()
- InstanceData.Parent = Player
- local PlayerData = PlayerDataService.new(Player.UserId)
- UpdateInstance(InstanceData,"Level", "Current", PlayerData.Level.Current)
- UpdateInstance(InstanceData,"Level", "EXP", math.floor(PlayerData.Level.EXP))
- UpdateInstance(InstanceData,"Level", "RequiredEXP", math.floor(PlayerData.Level.Current * PlayerData.Level.Multiplier))
- UpdateInstance(InstanceData,"Stats", "Health", PlayerData.Stats.Health)
- UpdateInstance(InstanceData,"Stats", "Points", PlayerData.Stats.Points)
- UpdateInstance(InstanceData,"Stats", "Stamina", PlayerData.Stats.Stamina)
- UpdateInstance(InstanceData,"Stats", "Strength", PlayerData.Stats.Strength)
- UpdateInstance(InstanceData,"Stats", "Quirk", PlayerData.Stats.Quirk)
- UpdateInstance(InstanceData,"Quirk", "Ability", PlayerData.Quirk.Ability)
- UpdateInstance(InstanceData,"Quirk", "Level", PlayerData.Quirk.Level)
- UpdateInstance(InstanceData,"Quirk", "EXP", PlayerData.Quirk.EXP)
- UpdateInstance(InstanceData,nil, "MaxHealth", PlayerData.HP.Base + ( ( PlayerData.Level.Current * PlayerData.HP.Multiplier.Level ) + ( PlayerData.Stats.Health * PlayerData.HP.Multiplier.Point ) ) )
- UpdateInstance(InstanceData,"Stamina", "Max", PlayerData.Stamina.Base + ((PlayerData.Level.Current * PlayerData.Stamina.Multiplier.Level) + (PlayerData.Stats.Stamina * PlayerData.Stamina.Multiplier.Point)))
- UpdateInstance(InstanceData,"Stats", "Points", PlayerData.Stats.Points)
- UpdateInstance(InstanceData,nil, "Yen", PlayerData.Yen)
- UpdateInstance(InstanceData,"Spins", "Common", PlayerData.Spins.Common)
- UpdateInstance(InstanceData,"Spins", "Uncommon", PlayerData.Spins.Uncommon)
- UpdateInstance(InstanceData,"Spins", "Rare", PlayerData.Spins.Rare)
- UpdateInstance(InstanceData,"Spins", "PlusUltra", PlayerData.Spins.PlusUltra)
- end
- end)
- end)
- return PlayerDataService
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement