Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i save tools with data store 2?

Asked by 3 years ago
Edited 3 years ago

First of all, i used a diferent method to save and load stuff because it feels more easy and i wont change it, i just want to know how could i save tools with this method, i tried to save tools but i couldnt, theres a shop where you buy the tools and puts it on your inventory.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")

local DataStore2 = require(1936396537)

-- Always "combine" any key you use! To understand why, read the "Gotchas" page.
DataStore2.Combine("lol", "Level", "Exp", "MaxExp", "Zenni", "SP", "Target", "TargetsLeft", "Quest", "KM", "MaxKi", "MH", "MaxHeath", "MStore", "KD","MD" , "R", "S", "Q", "QT", "QN", "ZR", "ER", "DO", "QNC", "Attacks")

Players.PlayerAdded:Connect(function(player)
    local function Load(Character)
        local StoreLevel = DataStore2("Level", player)
        local StoreExp = DataStore2("Exp", player)
        local StoreZenni = DataStore2("Zenni", player)
        local StoreMaxExp = DataStore2("MaxExp", player)
        local StoreSP = DataStore2("SP", player)
        local StoreTarget = DataStore2("Target", player)
        local StoreQuest = DataStore2("Quest", player)
        local StoreTargetsLeft = DataStore2("TargetsLeft", player)
        local StoreKM = DataStore2("KM", player)
        local StoreMaxKi = DataStore2("MaxKi", player)
        local StoreMH = DataStore2("MH", player)
        local StoreMaxHealth = DataStore2("MaxHealth", player)
        local StoreMD = DataStore2("MD", player)
        local StoreKD = DataStore2("KD", player)
        local StoreR = DataStore2("R", player)
        local StoreS = DataStore2("S", player)
        local StoreQ = DataStore2("Q", player)
        local StoreQT = DataStore2("QT", player)
        local StoreQN = DataStore2("QN", player)
        local StoreQNC = DataStore2("QNC", player)
        local SER = DataStore2("ER", player)
        local SZR = DataStore2("ZR", player)
        local SDO = DataStore2("DO", player)
        local SAttacks = DataStore2("Attacks", player)

        local Level = player.Character:WaitForChild("Level",1)
        local Exp = player.Character:WaitForChild("EXP",1)
        local MaxExp = player.Character:WaitForChild("MaxExp",1)
        local Zenni = player.Character:WaitForChild("Zenni",1)
        local SP = player.Character:WaitForChild("SP",1)
        local Target = player.Character:WaitForChild("Target",1)
        local Quest = player.Character:WaitForChild("Quest",1)
        local TargetsLeft = player.Character:WaitForChild("TargetsLeft",1)
        local KM = player.Character:WaitForChild("KM",1)
        local HM = player.Character:WaitForChild("MH",1)
        local MaxKi = player.Character:WaitForChild("MaxKi",1)
        local HealthMax = player.Character:WaitForChild("Humanoid",1).MaxHealth
        local MD = player.Character:WaitForChild("MD",1)
        local KD = player.Character:WaitForChild("KD",1)
        local S = player.Character:WaitForChild("Speed",1)
        local R = player.Character:WaitForChild("Resistance",1)
        local Q = player:WaitForChild("PlayerGui",1):WaitForChild("Main",1).Quest
        local QT = player:WaitForChild("PlayerGui",1):WaitForChild("Main",1).Questt
        local QN =  player.Character:WaitForChild("QuestName").Value
        local QNC =  player.Character:WaitForChild("QuestName",1)
        local ZR = player.Character:WaitForChild("ZR",1)
        local ER =  player.Character:WaitForChild("ER",1)
        local DO =  player.Character:WaitForChild("Do",1)
        local Attacks =  player.Character:WaitForChild("Attacks",1)

        if StoreLevel:Get() ~= nil then
            Level.Value = StoreLevel:Get()
        else
            Level.Value = 1
        end

        if StoreExp:Get() ~= nil then
            Exp.Value = StoreExp:Get()
        else
            Exp.Value = 0
        end
        if StoreMaxExp:Get() ~= nil then
            MaxExp.Value = StoreMaxExp:Get()
        else
            MaxExp.Value = 100
        end

        if StoreZenni:Get() ~= nil then
            Zenni.Value = StoreZenni:Get()
        else
            Zenni.Value = 1000
        end

        if StoreSP:Get() ~= nil then
            SP.Value = StoreSP:Get()
        else
            SP.Value = 3
        end

        if StoreQuest:Get() ~= nil then
            Quest.Value = StoreQuest:Get()
        else
            Quest.Value = false
        end

        if StoreTarget:Get() ~= nil then
            Target.Value = StoreTarget:Get()
        else
            Target.Value = "None"
        end

        if StoreTargetsLeft:Get() ~= nil then
            TargetsLeft.Value = StoreTargetsLeft:Get()
        else
            TargetsLeft.Value = 0
        end

        if StoreMH:Get() ~= nil then
            HM.Value = StoreMH:Get()
        else
            HM.Value = 1
        end

        if StoreKM:Get() ~= nil then
            KM.Value = StoreKM:Get()
        else
            KM.Value = 1
        end

        if StoreMaxKi:Get() ~= nil then
            MaxKi.Value = StoreMaxKi:Get()
        else
            MaxKi.Value = 100
        end

        if StoreMaxHealth:Get() ~= nil then
            HealthMax = StoreMaxHealth:Get()
        else
            HealthMax = 100
        end

        if StoreKD:Get() ~= nil then
            KD.Value = StoreKD:Get()
        else
            KD.Value = 1
        end

        if StoreMD:Get() ~= nil then
            MD.Value = StoreMD:Get()
        else
            MD.Value = 1
        end

        if StoreS:Get() ~= nil then
            S.Value = StoreS:Get()
        else
            S.Value = 1
        end

        if StoreR:Get() ~= nil then
            R.Value = StoreR:Get()
        else
            R.Value = 1
        end

        if StoreQ:Get() ~= nil then
            Q.Visible = StoreQ:Get()
        else
            Q.Visible = false
        end

        if StoreQT:Get() ~= nil then
            QT.Visible = StoreQT:Get()
        else
            QT.Visible = false
        end

        if StoreQNC:Get() ~= nil then
            QNC.Value = StoreQNC:Get()
        else
            QNC.Value = "None"
        end

        if StoreQ:Get() ~= nil then
            Q.Text = StoreQNC:Get()
        else
            Q.Text = "None"
        end

        if SZR:Get() ~= nil then
            ZR.Value = SZR:Get()
        else
            ZR.Value = "None"
        end

        if SER:Get() ~= nil then
            ER.Value = SER:Get()
        else
            ER.Value = "None"
        end

        if SDO:Get() ~= nil then
            DO.Value = SDO:Get()
        else
            DO.Value = "None"
        end

        if SAttacks:Get() ~= nil then
            Attacks:Destroy()
            print("destroyed")
            SAttacks:Get().Parent = Character
            print("parented")
        end

        --//SAVE

        Level.Changed:Connect(function()
            StoreLevel:Set(Level.Value)
        end)
        Exp.Changed:Connect(function()
            StoreExp:Set(Exp.Value)
        end)

        MaxExp.Changed:Connect(function()
            StoreMaxExp:Set(MaxExp.Value)
        end)

        Zenni.Changed:Connect(function()
            StoreZenni:Set(Zenni.Value)
        end)

        SP.Changed:Connect(function()
            StoreSP:Set(SP.Value)
        end)

        Quest.Changed:Connect(function()
            StoreQuest:Set(Quest.Value)
        end)

        Target.Changed:Connect(function()
            StoreTarget:Set(Target.Value)
        end)

        TargetsLeft.Changed:Connect(function()
            StoreTargetsLeft:Set(TargetsLeft.Value)
        end)

        HM.Changed:Connect(function()
            StoreMH:Set(HM.Value)
        end)

        Character.Humanoid:GetPropertyChangedSignal("MaxHealth"):Connect(function()
            StoreMaxHealth:Set(HealthMax)
        end)

        KM.Changed:Connect(function()
            StoreKM:Set(KM.Value)
        end)

        MaxKi.Changed:Connect(function()
            StoreMaxKi:Set(MaxKi.Value)
        end)

        MD.Changed:Connect(function()
            StoreMD:Set(MD.Value)
        end)

        KD.Changed:Connect(function()
            StoreKD:Set(KD.Value)
        end)

        S.Changed:Connect(function()
            StoreS:Set(S.Value)
        end)

        R.Changed:Connect(function()
            StoreR:Set(R.Value)
        end)
        Q:GetPropertyChangedSignal("Visible"):Connect(function()
            StoreQ:Set(Q.Visible)
        end)
        QT:GetPropertyChangedSignal("Visible"):Connect(function()
            StoreQT:Set(QT.Visible)
        end)
        QNC.Changed:Connect(function()
            StoreQNC:Set(QNC.Value)
        end)

        ZR.Changed:Connect(function()
            SZR:Set(ZR.Value)
        end)

        ER.Changed:Connect(function()
            SER:Set(ER.Value)
        end)

        DO.Changed:Connect(function()
            SDO:Set(DO.Value)
        end)

        Character.Attacks.ChildAdded:Connect(function()
            print("boi")
            SAttacks:Set(Attacks)
        end)
    end
    player.CharacterAdded:Connect(Load)
end)

Answer this question