Datastore doesnt save bool value instance

Hi!, im making a codes script which saves which codes you have used by placing a bool value into the player and then saving and loading the instance then checking if its there however, the instance of the bool value doesnt save

local DS = game:GetService("DataStoreService"):GetDataStore("Code3")

game.Players.PlayerAdded:Connect(function(player)
	wait()
	local plrKey = "id_"..player.UserId
	local getSaved = DS:GetAsync(plrKey)
	if getSaved then
		for i, v in pairs(getSaved) do
			local temp = Instance.new("BoolValue", player.Codes)
			temp.Name = v
		end
	else
		local ValuesForSaving = {}
		for i, v in pairs(player.Codes:GetChildren()) do
			table.insert(ValuesForSaving, v.Name)
		end
		DS:SetAsync(plrKey, ValuesForSaving)
		
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local savevalues = {}
	
	for i, v in pairs(player.Codes:GetChildren()) do
		table.insert(savevalues, v.Name)
	end
	DS:GetAsync("id_"..player.UserId)
end)





Of course you can’t save a bool value instance, you have to save the value

1 Like

You have made a typo in the PlayerRemoving function.

Replace the DS:GetAsync("id_"..player.UserId) with DS:SetAsync("id_"..player.UserId, savevalues)

1 Like

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