Data Store Not Saving When It Should

Hi,
I am working on this settings system, and I am attempting to data save a bool value for audio. However, it seems that the data is either not saving or not loading. I used this script for other values, and it works fine. I don’t see any reason for it not to be working. Also, before you point out how its in workspace and not changing for every player, the game is single-player and its easier to put it in workspace so I can access it easily. Here is the server script:

local dataStore = game:GetService('DataStoreService'):GetDataStore('AudioSet')
game:GetService('Players').PlayerAdded:Connect(function(plr)
	local value = Instance.new('BoolValue')
	value.Name = 'AudioOn'
	value.Parent = workspace
	

	local data

	
	local success, result = pcall(function()
		data = dataStore:GetAsync("Player_"..plr.UserId)
	end)

	if success then
		if data then
			value.Value = data
		else
			value.Value = true
		end
	end



	wait(1)
	if value.Value == false then
		game:GetService('ReplicatedStorage'):FindFirstChild('Events').Tirm:FireClient(plr)
print('sent')
	end
	print(value.Value)

end)




game.Players.PlayerRemoving:Connect(function(player)	
	local success, result = pcall(function()
		dataStore:SetAsync("Player_"..player.UserId, workspace.AudioOn.Value)
	end)	

	if success then
		print(result)
	else
		warn(result)
	end
end)

game:BindToClose(function()
	for _, player in ipairs(game.Players:GetPlayers()) do

		local success, result = pcall(function()
			dataStore:SetAsync("Player_"..player.UserId, workspace.AudioOn.Value)
		end)


		end
end)




local Storage = game:GetService('ReplicatedStorage')
Storage.Events.Settings.OnServerEvent:Connect(function(Player, value)
	if value == 'True' then
		workspace.AudioOn.Value = true
		print('going true')
	elseif value == 'False' then
		workspace.AudioOn.Value = false
		print('going false')
	end

end)

Whenever the player presses a textbutton, it fires the even and make the value go either true or false. For some reason, I am getting no errors but it just- isn’t saving/loading the bool value. Any help would be appreicated.

1 Like

What gets printed to the output?

I reckon you’ll have issues when multiple players join too as they all use the same workspace.AudioOn object.

You see, this game is a singleplayer game so thats why I used workspace. Also, nothing really gets printed in output. Whenever the value is changed in one game instance, it just doesn’t get saved/loaded.

Are you changing the value from a local script or a server script?

make sure you have a system for setting up a new datastore for a player if its their first time playing the game

In the script, a event is firing to the server changing the value on the server.

Did you go to Game Settings → Security → Enable Studio Access to API Services and turn it on?

1 Like

Yes… it is on. I have a couple other data store scripts using this method, except this is the only one that wont work. I guess I’ll just try redoing the script since I havent found much of a solution yet.

Remade it and it worked. I can close this now.