Cannot save two boolean values

So I’ve been making a settings system for my game which saves but the saving part doesn’t work at all. I’ve tried to look for a solution but all of them failed soooo yeah here we are

script:

local DataStoreService = game:GetService("DataStoreService")
local SettingDataStore = DataStoreService:GetDataStore("Settings")

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	local UserID = player.UserId
	local key = "Player_".. UserID
	
	local Config = Instance.new("Configuration")
	Config.Name = "Settings"
	Config.Parent = player

	local ViewBobbingToggle = Instance.new("BoolValue")
	ViewBobbingToggle.Name = "ViewBobbing"
	ViewBobbingToggle.Value = true
	ViewBobbingToggle.Parent = Config

	local MotionBlurToggle = Instance.new("BoolValue")
	MotionBlurToggle.Name = "MotionBlur"
	MotionBlurToggle.Value = true
	MotionBlurToggle.Parent = Config
	
	local SettingsData
	local success, errormessage = pcall(function()
		SettingsData = SettingDataStore:GetAsync(key)
	end)
	
	if success then
		if SettingsData ~= nil then
			Config:FindFirstChild("MotionBlur").Value = SettingsData[1]
			Config:FindFirstChild("ViewBobbing").Value = SettingsData[2]
		else
			Config:FindFirstChild("MotionBlur").Value = true
			Config:FindFirstChild("ViewBobbing").Value = true
		end
	else
		warn(errormessage)
	end

end)

Players.PlayerRemoving:Connect(function(player)
	local Config = player:WaitForChild("Settings")
	local UserID = player.UserId
	local key = "Player_".. UserID
	
	local MotionBlurValue = Config:FindFirstChild("MotionBlur").Value
	local ViewBobbingValue = Config:FindFirstChild("ViewBobbing").Value
	
	local success, errormessage = pcall(function()
		SettingDataStore:SetAsync(key, {MotionBlurValue, ViewBobbingValue})
	end)
	
	if success then
		print("Saved!")
	else
		warn(errormessage)
	end
	
end)

game:BindToClose(function()
	task.wait(1)
end)

Edit: I found out that it works BUT will always save as false idk just something to help out find the issue ig

Instead of defining the value in the variable, try using the .Value in the table:

local MotionBlurValue = Config:FindFirstChild("MotionBlur")
local ViewBobbingValue = Config:FindFirstChild("ViewBobbing")
	
local success, errormessage = pcall(function()
	SettingDataStore:SetAsync(key, {MotionBlurValue.Value, ViewBobbingValue.Value})
end)

it still doesn’t work (30charbypass)

hey uhh i figured it out soo i changed the values locally and it is saved on the servers and fixed it myself

thanks for trying

1 Like

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