Help when Copying data to the value

  • This has been my 3rd post(in this devforum & about DataStore2), the title topic is self-explanatory.

  • For a little context, when I try copying data variable and when I put ExampleVariable.Value = data it doesn’t change the ExampleVariable for my problem.

  • Extra Context: This are created in the game:GetService('ServerStorage') and the Cash is in player

  • There were no errors or anything but the tables that were printed shows the values but not editing in the player.

Script:

-- Data Var:
local dss: DataStoreService = game:GetService('DataStoreService')
local ds: DataStore = dss:GetDataStore('ClientData')

-- Players:
local plrs: Players = game:GetService('Players')

-- Function:

-- Duplicated DataFolder to Player

local function DuplicatedData(plr: Player)
	local DataFolder: Folder = game:GetService('ServerStorage').DataFolder -- Main DataFolder
	
	local DataStorageFolders: Folder = DataFolder:GetChildren()
	
	for index, folder in DataStorageFolders do
		for _, values in folder:GetChildren() do
			local dupfolder = folder:Clone()
			dupfolder.Parent = plr
		end
	end	
end
-- On Player Joining --

local function OnLoadClientData(plr: Player)
	local data = nil
	
	local playerKey = plr.UserId -- key
	
	local success, err = pcall(function()
		data = ds:GetAsync(playerKey)		
	end)
	
	local KickMessage = 'Server could not load your data'
	
	if not success then plr:Kick(KickMessage) return end
	
	DuplicatedData(plr)

	local DataFolder: Folder = plr:WaitForChild('1')
	
	local Values: IntValue = DataFolder:GetChildren()
	
	for _, v in Values do
		for i, value in data do
			
			Values.Value = value
			
		end		
	end	
	print('Loaded: ', data)
end

-- On Player Leaving --

local function OnSaveClientData(plr: Player)
		
	local data = nil

	local playerKey = plr.UserId -- key

	local DataFolder: Folder = plr:WaitForChild('1')

	local dataTab = {
		
		DataFolder:WaitForChild('Cash').Value
		
	}
	
	local success, err = pcall(function()
		data = ds:SetAsync(playerKey, dataTab)
	end)
	
	if success then 
		print('Saved: ', dataTab)
	else		
		warn('Server Could Not Save Data')

	end
end

plrs.PlayerAdded:Connect(OnLoadClientData) -- Load Data
plrs.PlayerRemoving:Connect(OnSaveClientData) -- Save Data

You are saving a table which consists of only one element.

Then, you tried to cycle through the whole data table to load the data.

Do you meant to use the v variable in the Values for loop? Because you are indexing Values and indexing its Value property and setting it to the one element in your data table.

Should I delete the for _, v in Values and try for i, value in data only?

You have given me the idea, thank you @ItzMeZeus_IGotHacked

  • I have finally found the solution I just had to remove the for _, v in Values do

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.