DataSave problem

Hello,

First sorry for my bad english.

I have problem with Data Saving in my game.
Data don t saving properly and loading too.

Here is the script from ServerScriptService:

--// VARIABLES //--
local FolderName                          = 'Numbers'
local AutoSave                            = true
local WaitTime                            = 120
local AutosaveIcon                        = true
local SaveOnLeaving                       = true
local DataStoreName                       = 'ShopSimulatorSHHData'
local SaveOnShutdown                      = true
local SayToSave                           = 'SaveGameData'
local DataStore                           = game:GetService("DataStoreService"):GetDataStore(DataStoreName)
local ShutDown                            = false
local ReplicatedStorage                   = game:GetService("ReplicatedStorage")
local event                               = Instance.new("BindableEvent",game.Workspace)
event.Name                                = "PlayerChattedEvent"
	
--// FUNCTIONS //--

--// ON ENTERED //--
function OnEntered(plr)
	local Numbers = ReplicatedStorage.Numbers:Clone()
	Numbers.Parent = plr	
    wait(.3)
	repeat wait(.1) until plr:FindFirstChild(FolderName)
	local key = "User_"..plr.UserId
	if plr[FolderName] then
		local values = plr[FolderName]:GetChildren()
		if DataStore:GetAsync(key) then
			for i, l in pairs(values) do
				if DataStore:GetAsync(key)[i] then
					l.Value = DataStore:GetAsync(key)[i]
				end
			end
			print(plr.Name.."'s Data is loaded")
		else
			local array2 = {}
			for i, c in pairs(values) do
				table.insert(array2,i,c.Value)
			end
			DataStore:SetAsync(key, array2)
			print("Data created for "..plr.Name)
		end
	else
		warn("Cannot find "..FolderName.." In "..plr.Name..", Did you typed the wrong name?")
	end
end

--// ON CHATTED //--
function OnChatted(plr,msg)
	if msg == SayToSave then
	if AutosaveIcon == true then
		script.Saving.Event:Fire(plr)
	end
	local array = {}
	local key = "User_"..plr.UserId
	if plr[FolderName] then
		local vl2 = plr[FolderName]:GetChildren()
		for i, k in pairs(vl2) do
			table.insert(array,i,k.Value)
		end
		DataStore:SetAsync(key, array)
		print("Data manually saved for "..plr.Name)
	end
	end
end

--// ON LEAVING //--
function OnLeaving(Lplr)
	wait(.1)
	if ShutDown == true then
		if SaveOnLeaving == true then
		 local key = "User_"..Lplr.UserId
	     if Lplr[FolderName] then
		    local Larray = {}
		    local vl3 = Lplr[FolderName]:GetChildren()
		     for i, a in pairs(vl3) do
			    table.insert(Larray,i,a.Value)
		     end
		    DataStore:SetAsync(key, Larray)
		    print(Lplr.Name.."'s Data was saved while leaving")
	    end
		else
			print("Save on leaving is off")
		end
	end
end

--// ON SAVE //--
function OnSave()
	for i, Nplr in pairs(game.Players:GetChildren()) do
		if AutosaveIcon == true then
			script.Saving.Event:Fire(Nplr)
		end
		local array = {}
		local key = "User_"..Nplr.UserId
		if Nplr[FolderName] then
			local vl2 = Nplr[FolderName]:GetChildren()
			for i, k in pairs(vl2) do
				table.insert(array,i,k.Value)
			end
			DataStore:SetAsync(key, array)
			print("Data automatically saved for "..Nplr.Name)
		end
	end
end

--// BIND TO CLOSE //--
game:BindToClose(function()
	if SaveOnShutdown == true then
		ShutDown = true
		for i, Nplr in pairs(game.Players:GetChildren()) do
			local array = {}
			local key = "User_"..Nplr.UserId
			if Nplr[FolderName] then
				local vl2 = Nplr[FolderName]:GetChildren()
				for i, k in pairs(vl2) do
					table.insert(array,i,k.Value)
				end
				DataStore:SetAsync(key, array)
				print("Data automatically saved for "..Nplr.Name.." Before shutdown")
			end
		end
	else
		print("SaveOnShutdown is off")
	end
end)

--// PLAYER CHATTED CONNECT //--
game.Workspace.PlayerChattedEvent.Event:connect(function(plr,msg)
	OnChatted(plr,msg)
end)
--// PLAYER ADDED CONNECT //--
game.Players.PlayerAdded:connect(function(plr)
	OnEntered(plr)
end)
--// PLAYER REMOVING CONNECT //--
game.Players.PlayerRemoving:connect(function(Lplr)
	OnLeaving(Lplr)
end)

--// AUTO SAVE //--
while wait(WaitTime) do
	if AutoSave == true then
		OnSave()
	else
		print("AutoSave is off")
		break
	end
end

And here is Numbers from ReplicatedStorage: ALL IS INTVALUE

V%C3%BDst%C5%99i%C5%BEek1

Icon what show when Auto Saving is active:

V%C3%BDst%C5%99i%C5%BEek2

CloneScript:
V%C3%BDst%C5%99i%C5%BEek4

Circle image:

V%C3%BDst%C5%99i%C5%BEek6

Would it be OK if you elaborate on what is going wrong with your data? Is it outputting an error? I the data being saved incorrectly? Or is something else going wrong?

Also, please can you state what each of your scripts do. At the moment, we have to make an educated guess.

I can’t get a read of what exactly the problem is. State your issue of the scripts and the exact expected behavior of the system.

Which of these describes the problem?


  • Generally saving; it’s not saving
  • Signal not firing when chatting; perhaps you’re looking for RemoteEvent.

Analysis:
The saving method is not really effective, I usually rely on a table where I store all the values and update them there instead of the IntValue practice; although this should work.

You are saving a key for each intValues separately, that most likely is causing throttling.

You need to store these values in a table ({1,5,2}). That way, you will not be throttled.

1 Like

@CodeNinja16 @anon81993163 @REALTimothy0812

Thank you guys :+1: