local DS = game:GetService("DataStoreService"):GetDataStore("ALPHA_MALE")

game.Players.PlayerAdded:Connect(function(players)
--Key
local Key = 'ID-' ..players.UserId			
--Loading Values
game.ServerStorage:WaitForChild("Stands")
local plrfile = game.ServerStorage.Stands:WaitForChild(players.Name)
local STypes = plrfile:WaitForChild("STypes")
local SStats = plrfile:WaitForChild("SStats")

local CR = STypes:WaitForChild("CR")
local LR = STypes:WaitForChild("LR")
local Auto = STypes:WaitForChild("Auto")
local Bound = STypes:WaitForChild("Bound")
local Colony = STypes:WaitForChild("Colo")
local Wear = STypes:WaitForChild("Wear")

local POW = SStats:WaitForChild("POW")
local SPD = SStats:WaitForChild("SPD")
local RNG = SStats:WaitForChild("RNG")
local DUR = SStats:WaitForChild("DUR")
local PER = SStats:WaitForChild("PER")
local LER = SStats:WaitForChild("LER")
--Table Store
local StoringTable = {}
--Get Data and Store
local Save_Load = DS:GetAsync(Key)
--Def Val
	if Save_Load ~= nil then
		if #Save_Load >= 1 then
			print("Has Data")
			--[[if Save_Load[] ~= nil then
                --.Value = Save_Load[]
                --table.insert(StoringTable , Save_Load[])
				--end]]
			if Save_Load[1] ~= nil then
                CR.Value = Save_Load[1]
				table.insert(StoringTable , Save_Load[1])
			end
			if Save_Load[2] ~= nil then
                LR.Value = Save_Load[2]
				table.insert(StoringTable , Save_Load[2])
            end
			if Save_Load[3] ~= nil then
                Auto.Value = Save_Load[3]
                table.insert(StoringTable , Save_Load[3])
			end
			if Save_Load[4] ~= nil then
                Bound.Value = Save_Load[4]
                table.insert(StoringTable , Save_Load[4])
			end
			if Save_Load[5] ~= nil then
                Colony.Value = Save_Load[5]
                table.insert(StoringTable , Save_Load[5])
			end
			if Save_Load[6] ~= nil then
                Wear.Value = Save_Load[6]
                table.insert(StoringTable , Save_Load[6])
			end
			if Save_Load[7] ~= nil then
                POW.Value = Save_Load[7]
                table.insert(StoringTable , Save_Load[7])
			end
			if Save_Load[8] ~= nil then
                SPD.Value = Save_Load[8]
                table.insert(StoringTable , Save_Load[8])
			end
			if Save_Load[9] ~= nil then
                RNG.Value = Save_Load[9]
                table.insert(StoringTable , Save_Load[9])
			end
			if Save_Load[10] ~= nil then
                DUR.Value = Save_Load[10]
                table.insert(StoringTable , Save_Load[10])
			end
			if Save_Load[11] ~= nil then
                PER.Value = Save_Load[11]
                table.insert(StoringTable , Save_Load[11])
			end
			if Save_Load[12] ~= nil then
                LER.Value = Save_Load[12]
                table.insert(StoringTable , Save_Load[12])
			end
		print(Save_Load[1],Save_Load[2],Save_Load[3],Save_Load[4],Save_Load[5],Save_Load[6],Save_Load[7],Save_Load[8],Save_Load[9],Save_Load[10],Save_Load[11],Save_Load[12])
	else
		Save_Load = {}
		Save_Load[1] = CR.Value 
        CR.Value = nil
        table.insert(StoringTable , Save_Load[1])
		Save_Load[2] = LR.Value 
        LR.Value = nil
        table.insert(StoringTable , Save_Load[2])
		Save_Load[3] = Auto.Value 
        Auto.Value = nil
        table.insert(StoringTable , Save_Load[3])
		Save_Load[4] = Bound.Value 
        Bound.Value = nil
        table.insert(StoringTable , Save_Load[4])
		Save_Load[5] = Colony.Value 
        Colony.Value = nil
        table.insert(StoringTable , Save_Load[5])
		Save_Load[6] = Wear.Value 
        Wear.Value = nil
        table.insert(StoringTable , Save_Load[6])
		Save_Load[7] = POW.Value 
        POW.Value = nil
        table.insert(StoringTable , Save_Load[7])
		Save_Load[8] = SPD.Value 
        SPD.Value = nil
        table.insert(StoringTable , Save_Load[8])
		Save_Load[9] = RNG.Value 
        RNG.Value = nil
        table.insert(StoringTable , Save_Load[9])
		Save_Load[10] = DUR.Value 
        DUR.Value = nil
        table.insert(StoringTable , Save_Load[10])
		Save_Load[11] = PER.Value 
        PER.Value = nil
        table.insert(StoringTable , Save_Load[11])
		Save_Load[12] = LER.Value 
        LER.Value = nil
        table.insert(StoringTable , Save_Load[12])
		print(Save_Load[1],Save_Load[2],Save_Load[3],Save_Load[4],Save_Load[5],Save_Load[6],Save_Load[7],Save_Load[8],Save_Load[9],Save_Load[10],Save_Load[11],Save_Load[12])
		DS:SetAsync(Key, StoringTable)
		end	
	end
end)

game.Players.PlayerRemoving:Connect(function(players)
--Key
local Key = 'ID-' ..players.UserId	
--Loading Vals
game.ServerStorage:WaitForChild("Stands")
local plrfile = game.ServerStorage.Stands:WaitForChild(players.Name)
local STypes = plrfile:WaitForChild("STypes")
local SStats = plrfile:WaitForChild("SStats")

local CR = STypes:WaitForChild("CR")
local LR = STypes:WaitForChild("LR")
local Auto = STypes:WaitForChild("Auto")
local Bound = STypes:WaitForChild("Bound")
local Colony = STypes:WaitForChild("Colo")
local Wear = STypes:WaitForChild("Wear")

local POW = SStats:WaitForChild("POW")
local SPD = SStats:WaitForChild("SPD")
local RNG = SStats:WaitForChild("RNG")
local DUR = SStats:WaitForChild("DUR")
local PER = SStats:WaitForChild("PER")
local LER = SStats:WaitForChild("LER")
--Saving	
local DataToSave = {
CR.Value,
LR.Value,
Auto.Value,
Bound.Value,
Colony.Value,
Wear.Value,

POW.Value,
SPD.Value,
RNG.Value,
DUR.Value,
PER.Value,
LER.Value,	
	
	
}
DS:SetAsync(Key, DataToSave)

end)

It's saving when the person resets or leave the game, but as soon as the server shutdowns the values are no longer saved. I've been told to use SetAsync but it hasn't been working... Can someone help?

3 comments

0

Use BindToClose ;-;

0

Can you explain a bit more?

0

while wait(3) do stats.Value:SetAsync() end <-- that saves stuff every 3 secs