local SaveAddition = script.SaveAddition.Value DataStore = game:GetService("DataStoreService"):GetDataStore("OnePiece"..SaveAddition) local IntegerValues = { "Banking", "Swimming", "SwimmingExp", "SwimmingMaxExp", "HasCharacter", "Bullets", "Rum", "Crates", "HairStyle", "Quest", "Apples", "Corn", "Wheat", "CopperOre", "IronOre", "Handles", "AppleSlices" } local StringValues = { "DevilFruit", "Race", "Imprisoned", "Gender", "Occupation", "Skin" } local NumberValues = { "KenHaki", "BusoHaki", "HaoHaki", "HandWork", "FootWork", "SkinColorR", "SavedLocationX", "SavedLocationY", "SavedLocationZ", "Energy", "MaxEnergy", "Health", "MaxHealth", "Stomach", "MaxStomach", "Oxygen", "MaxOxygen", "Cooking", "Swordsmanship", "PowerOutput" } function SaveFunction(Player, DataType, DataHold, Table) print(Player.Name,DataType,"SAVING") local key = tostring(Player.userId..DataType) DataStore:UpdateAsync(key, function(oldD) D = {} for i = 1, #Table do local Val = DataHold[Table[i]] table.insert(D, i, Val.Value) end D = D return D end) print(Player.Name,DataType,"SAVED") end function Save(Player) while true do wait(60) print("SAVE"..Player.Name) local Data = game.ReplicatedStorage.DataFolder[Player.Name.."Data"] SaveFunction(Player, "Integer", Data, IntegerValues) SaveFunction(Player, "String", Data, StringValues) SaveFunction(Player, "Number", Data, NumberValues) print("SAVED"..Player.Name) end end function onPlayerEntered(Player) local DataStorage = game.ReplicatedStorage.DataFolder if DataStorage:FindFirstChild(Player.Name.."Data") ~= nil then DataStorage[Player.Name.."Data"]:remove() end local Data = Instance.new("IntValue", DataStorage) -- All of the Values for Data Go Inside of here. Data.Name = Player.Name.."Data" -- Insert Integer Values (If There's Any.) for InsertIntegers = 1, #IntegerValues do local NewInteger = Instance.new("IntValue", Data) NewInteger.Name = IntegerValues[InsertIntegers] NewInteger.Value = 0 end -- Insert String Values (If There's Any.) for InsertStrings = 1, #StringValues do local NewString = Instance.new("StringValue", Data) NewString.Name = StringValues[InsertStrings] NewString.Value = "" end -- Insert Number Values (If There's Any.) for InsertNumbers = 1, #NumberValues do local NewNumber = Instance.new("NumberValue", Data) NewNumber.Name = NumberValues[InsertNumbers] NewNumber.Value = 0 end if DataStore:GetAsync(Player.userId.."Integer") ~= nil then D = DataStore:GetAsync(Player.userId.."Integer") for i, v in pairs(D) do Data:FindFirstChild(IntegerValues[i]).Value = v end else end if DataStore:GetAsync(Player.userId.."String") ~= nil then D = DataStore:GetAsync(Player.userId.."String") for i, v in pairs(D) do Data:FindFirstChild(StringValues[i]).Value = v end else end if DataStore:GetAsync(Player.userId.."Number") ~= nil then D = DataStore:GetAsync(Player.userId.."Number") for i, v in pairs(D) do Data:FindFirstChild(NumberValues[i]).Value = v end else end local RunSave = coroutine.wrap(Save) RunSave(Player) end game.Players.ChildAdded:connect(onPlayerEntered)
Closed as Too Broad by RubenKan
This question has been closed because it is too broad and is generally unanswerable. Please ask a more specific question.
Why was this question closed?