The table's values are not changing even though it has been changed by in pairs loop

even though i used in pairs the table of settings are not changing, its still set as false even thought the “att” is set to true

-- Server
local Players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")
local DSS = game:GetService("DataStoreService")

local SettingsData = DSS:GetDataStore("SettingsDataStores")
local Data

local savedatas =
	
	{
		
		Reflections = false;
		Ambients = false;
		Extras = false;
		Shadows = false;
		other = false;
		
	}

Players.PlayerAdded:Connect(function(client)


	local Success, Error = pcall(function()
		Data = SettingsData:GetAsync(client.UserId)
	end)

	if Success and Data then
		RS.GuiEvents.ChangeSettings:FireClient(client, Data) -- Localize the textbox with your own path
	end
end)

RS.GuiEvents.SaveSettings.OnServerEvent:Connect(function(client, atts)
	
	local success, err = pcall(function()
		for attN,att in ipairs(atts) do 
		for savdN,savd in ipairs(savedatas) do
						
				if attN == savdN then
				
					savd = att
					
					print(att, attN, "Att")
					print(savd, savdN, "Saved")

					
				end	
			end
		end
		print(savedatas)
		SettingsData:SetAsync(client.UserId, savedatas)

		end)
	
	if not success then
		
		print(err)
		
	end
	
end)

Here you do not change the table, but simply change the value (savd = att), which does not affect anything
Try it:

local tosave = {}
for attN,att in ipairs(atts) do 
	for savdN,savd in ipairs(savedatas) do
		if attN == savdN then
			tosave[savdN] = att
			print(att, attN, "Att")
			print(savd, savdN, "Saved")
		end	
	end
end
print(tosave)
SettingsData:SetAsync(client.UserId, tosave)

do i put the

		Reflections = false;
		Ambients = false;
		Extras = false;
		Shadows = false;
		other = false;

inside the tosave table?

No! Everything is ready, you just need to insert into the script

i did some changes and it worked very appreciated

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